Hello Sir.....
What is static class and why are you make any class are static in c#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Abhishek KumarPosted May 30, 2014, 11:25 AM
what is static class:-
If a class is declared as static then the variables and methods should compulsorily be declared as static. A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
static class school
{
//All static member variables
static int schoolID; //College Id will be same for all the students studying
static string schoolName//Name will be same
static string Address; //Address of the college will also same
//Member functions
public static int GetCollegeId()
{
schoolID; = 100;
return (schoolID);
}
}
features of static class
•They only contain static members.
•They cannot be instantiated.
•They are sealed.
•They cannot contain Instance Constructors or simply constructors as we know that they are associated with objects and operates on data when an object is created
Why Static class
JobPencilPosted May 30, 2014, 9:03 AM
http://stackoverflow.com/questions/241339/when-to-use-static-classes-in-c-sharp
http://www.codeproject.com/Articles/11857/Introducing-C-static-classes
Thankyou
Find IT Jobs
Abhay ShankerPosted May 28, 2014, 12:32 PM
for more detail please check below urls
http://www.c-sharpcorner.com/uploadfile/hirendra_singh/static-classes-in-C-Sharp/
http://www.dotnetperls.com/static-class
VulpesPosted May 28, 2014, 11:31 AM
Static members for this purpose include constants and nested types.
A static class cannot have an instance constructor and so cannot be instantiated. However, they can contain a static constructor.
Static classes are implicitly sealed and so cannot be inherited from but they themselves inherit directly from System.Object.
Static classes are useful for gathering together a bunch of static members which have some relationship to one another. Examples in the .NET framework include System.Console and System.Math.
They can also be used as a repository for 'extension methods. For example : System.Linq.Enumerable or Queryable.
They are the closest thing which C# has to global functions and variables in some other languages. However, currently, the static member must always be qualified by the class name when called from outside its defining class though this is likely to change in the next version of C#.
For further details check this link:
http://msdn.microsoft.com/en-us/library/79b3xss3.aspx