Home > Articles > C# Articles > Static classes and static members in C#

Static classes and static members in C#

by Spidy   on Jan 10, 2011   Category: C#  | Level: Beginner  |  Views: 3785    |  Points: 100   
Like this article? Bookmark and Share:
In this article you will learn how to use static classes and methods in the .net projects.



The static classes and static members can be accessed without creating the object of the specific class. We cannot create the object for the static class. Non static methods only accessed through the instance of the class. if the class declared as a static and that class must contain only static members. By default static classes arce sealed. 

Generally the static methods are used to create static utility methods in the project as shown below

public static class GetInfo


        public static string GetFormattedDate(string Date)




                DateTime dt = Convert.ToDateTime(Date);

                return dt.ToString("dd/MM/yyyy");


            catch (Exception ex)


                throw ex;




        public static string GetUserDetails()


            //....return user info




Above is an sample static classes contains two methods that return date format and user details. Below is the way to accessing static methods.

Accessing static methods

string formatdDt = GetInfo.GetFormattedDate(DateTime.Now.ToString());

string Userdet = GetInfo.GetUserDetails();


In this way we can use static classes and utility methods in the projects.


Like this article? Bookmark and Share:

Most viewed Articles

User Comments

No response found, be the first to review this article.

Submit feedback about this article

Please sign in to post feedback

Latest Posts