.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

What scenarios make us to create static class and static methods?

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :ASP.Net


I am aware of the terminology "Static Member", "Static Class" and "Static Method"

Give some examples, What scenarios make us to use or create Static member, Static Class and Static Method?

View Complete Post

More Related Resource Links

ASP.NET: Using a static class and methods for the WCF client

Traditionally in our web pages we have instantiated a service client in each page and then called the WCF methods from that instance, adding some caching code to check if the data exists and if not, make the WCF call and cache the data for the next time. As our site grows we find we're repeating this same pattern and are looking to move it all to a single class. Can we make that class static, with a single static instance of the WCF client, and static methods, safely? // pseudo-code // assume WcfDataService has a GetFoo(int i) method public static class WcfMethods { public static WcfDataService client = new WcfDataService("connectionType"); public static DataSet GetFoo(int i) { if (Cache["foo" + i] == null) { Cache.Insert("foo" + i, client.GetFoo(i)); } return Cache["foo" + i] as DataSet; } } Then in our pages we can just call WcfMethods.GetFoo(x) directly.  Figure we have 100 users visiting our various pages simultaneously.  Will this cause contention issues?  Like I mentioned, up till now we've not used static instances.  It's not caused any problems, but we're just looking to refactor.  I realize we could also use the above pseudo-code pattern using an instance class and methods instead static ones. I haven't dealt with threading or synchro

Static Class for Beginners

In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

is there any impact of using static methods in Business Access layer in 3 tier applciation


is there any impact of using static methods in Business Access layer in 3 tier applciation,

Please suggest me what are the best practices and standards

Cache vs Static Class

Hi All, I am sure this question has been posted many times, but have not got time to wade through. Apologies in advance! I am working on a new web application which has extremely high volumes of traffic, the application uses two large(ish) data tables (approx 15,000 rows/records each - both fairly 'wide' tables....) which are each the result of various JOINS and other intensive operations. The post query operations are unavoidable and the data structure has been optimised wherever possible. I am debating on using the Cache and CacheDependancy classes to store these tables, but fear the 'eviction' process due to the demand in traffic and server resources generally. I can certainly afford to build these tables once, on the first request (near Application Start), but should memory become scarce, do not want the cached data to be recreated during the application lifecycle and have concerns about how ASP.NET will manage demands on this data in such a crisis. For example, if during a period of time, available memory is at an all time low, I would anticipate that the CacheDependancy would keep recreating the tables for each request. (I don't know...) Note: The Cache API is not used elsewhere and the Application and Session scopes are hardly used. At present, I am using just a static class to store the two tables which works a

Working with System.IO.Path static class

Hello everyone. Today, I was exploring the System.IO namespace in .NET 4.0 on an ASP.NET web application where I came to few changes, comparing with the previous versions of .NET, related to the System.IO.Path static class. The Path class contains the same method names in .NET 2.0, 3.5 as well as 4.0, only (in .NET 4.0) new overloads are added to System.IO.Path.Combine() method. In the following blog post, I will show the usage of few methods belonging to the System.IO.Path static class, as well as, the changes in Combine() method added in .NET 4.0. Besides the first method that is available in the previous versions for combining two string paths, now in .NET 4.0 you can combine unlimited strings to the path. Note: For testing purpose, on your web application root, create folders with name Files, Files/SubFolder, Files/SubSubFolder and add three text files: text1.txt (in Files), text2.txt (in Files/SubFolder), text3.txt (in Files/SubFolder/SubSubFolder).   Here are few examples:             string path1 = System.IO.Path.Combine(Server.MapPath("Files"), "text1.txt"); //this will give the path to %WEBAPP_ROOT%/Files/text1.text -             string path2 = System.IO.Path.Combine(Server.MapPath("Files"), "SubFolder", "text2.txt"); //this will give

Sharing of Non-Static member variables of a class using .NET Remoting

This kind of weird. I am trying to host an object of a class X (a class library class). This is a SAO and I have set the WellKnownMode as Singleton in the server configuration. <wellknown mode="Singleton" When multiple clients fetch the instance of the class X they can share the static member variables. Any changes made to the static variables are visible to each other. The problem is with the non-static member variables of the class. Each instance is having a local copy of the non-static variables. Why should that happen in case of a Singleton mode? Am I missing something for which this is happening? Any help will be appreciated.  A for apple, B for boy, C for c++

how to jquery call a other call function other class is not static

how to jquery call a other call function other class is not static[WebMethod]    public static bool Verify(string username, string password)    {        //Do your logic with username, password  here        //I am just checking with admin/admin credentials            Console.WriteLine("Ritu");        string s="SELECT p.RETMSG FROM P_DOCSHARE(1001,1453,'1002,1012,1011','Add') P";                 CCUtility c;                c=new CCUtility();             c.JavascriptMessage(c.Insert_P(s));        return (username == "admin" && password == "admin");    }

How to create static workflow using VS2010



I have two lists (myrequest and tasks). I want that whenever a item is added in myrequest list then automatically add a new task in task list and send notification to a particular address. Then once user open this new task and assign task to any assignee thne again send notification to assignee.

I want to create a common class for this, so it can be used in another project for different lists also. I want to implement this using VS2010 not thru SPD.

Please advise, if possible any url or tutorial to implement this step-by-step.


Calling a static method in a static class from a base class.


I have the following static class and method:

public static class GenericList


      public static List<DocumentElement> PopulateGenericList()



What is the syntax to call the PopulteGenericList() method from a base class?



WPF OneWay ItemsSource Binding to a static class's dictionary?



I have a global Static class which implements a dictionary of languages:

namespace Tools.DataAccess
  static public class Planner
    static public class Dictionaries
      static public Dictionary<UInt32, string> Languages { get; }

I am trying to bind a ComboBox's ItemSource to the static dictionary called "Languages". It works very well through code-behind at the moment:

ui_languages_cmo.ItemsSource = Tools.DataAccess.Planner.Dictionaries.Languages;

However I cannot bind it through XAML. The dictionary actually resides in a separate namespace (Tools) than my UserControl (myApp). Here's roughly what I'm trying to do:

<UserControl x:Class

How to add item into List<> in static Class


Hi, as above. Here the code.


1)Note :  Pictures is a collection of picture, PicNames is collection of names of pictures.

     MediaLibrary ml = new MediaLibrary();

            var ChkPics = ml.Pictures;
            var PicNames = from p in ChkPics
                           where p.Name.Contains("s")
                           select p;


2) Static Class

public static class PhotoNames
        private static List<string> m_Photoname = new List<string>();

        public static List<string> PhotoFileNames

How to make a published infopath form static when created from the doc library?


I have an infopath form that I published to a SharePoint Document Library. The fields in the infopath form pull from a Sharepoint list. When i create a new version of this form it pulls all the current data. And the columns in the document library reflect the correct information and I save to the Doc Library.

I then edit the information in the SharePoint List. When I look back at the Document Library the columns associated with my form i just created remain the same(referencing the information from when the form was created) But when I open the form it re querys the list and shows newly updated information. The columns seem to be static, but is there anyway to make the form static when it is saved? This way I can look at a form dated a week ago and see the info from last week, Open a new form and see the current info.



lifespan of a property inside a static class in IIS



I want to know , how good / bad is it to save configuration values in a static properties?

I am creating an application which reads configuration from an XML file and a DataContext file, instead of sending the CustomConfig class into the configuration.xml each time I tought about using an ReadXml() method on application_start at the global.ascx

the ReadXml() method would save the data in static properties of CustomConfig and whereever I would want to read that particler data I would ask CustomConfig.PROERTY_NAME

My question is ? how smart it is ? how long does IIS would save the data in a static member? (if as long as the application exists then I'm ok as long as I add the ReadXml() in the application_start)

would like to hear your comment.. 

Application variable or static class for global string?


I need to keep a global variable throughout the whole time the user is at my site, but do I use Application or a static class? The string variable should store a region name and my site makes a few changes depending on which region that has been set.

I read that Application was mainly for classic ASP, but I also read that a static class cannot be instantiated at runtime (e.g. when the user has logged in).

So, have I got something wrong here and which solution do I use?



How to create static Entity


Hi all,

How can I implement static entity in Dynamic Data + EF. For example, there are some values that is not stored in database, usually for simple categorization, like: M-Male, F-Female, or maybe 1-ABC, 2-DEF, 3-GHI. So, instead of creating a database table, just for few rows, is there a way I can create the entity on the model itself (or maybe use POCO?), but how to link it with Dynamic Data? Or is there any other better way?

I would like to know the best or most efficient solution for this case.

Thank you in advance.

Static "forms" used as a background to the XPS fixed pages to cut down the time to create XPS file



with Postscript I can define a resource (a static reusable form in this case) and reference that resource on any page I chose without having to recreate all the drawing instructions stored in that form resource.

How would I be able to do something similar with XPS?  Can I create a grouping of UIElements (drawing / text / image) as a resource stored at the FixedDocument level and then just include a reference to that resource on specific FixedPages?

Would seem illogical in the XPS file format to not be able to merge a single resource on the fixed pages which is a group of static UIElements which appear exactly the same on each of those pages.  Would cut down on repeat elements on every page and should end up with a smaller file size.



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend