Hi
done a lot of looking about and all the examples i find are too complex to grasp.
would one of you guys be good enough to try and explain a static class and some basic return types? i know viod acts like a sub, it doesnt return a value ... and i know that public string or public int will act as a function and return a value of the declared data type with its access modifier set to public, i know this from VB experience.
but im not too sure on static classes and members? ...just after a very basic explaination if poss,.
thanks in advance
Loading
Sam HobbsPosted Dec 16, 2010, 4:41 PM
The public in public string and public int does not refer to the return value; the public refers to the function and means that the function can be accessed from outside the class. If a function is not public then it can be called only from functions in the class.
Sam HobbsPosted Dec 18, 2010, 3:45 AM
You don't understand the unbelievable amount of time I voluntarily spend trying to help people such as you.
The point I am trying to make is that anything you can do to reduce the amount of our time that is required to help you is appreciated. When someone asks a question, then gets answers then decides to ask the same question again in a new thread without mentioning the previous assistance, it can waste time and most of the people that are willing to help you will not appreciate the waste of time.
So go ahead and reply to this, but I think I have said enough for now.
John BurnsPosted Dec 18, 2010, 3:16 AM
Sam HobbsPosted Dec 18, 2010, 3:07 AM
John BurnsPosted Dec 18, 2010, 2:24 AM
Sam HobbsPosted Dec 17, 2010, 8:42 PM
John BurnsPosted Dec 17, 2010, 2:15 AM
I can now understand static classes, actually not that difficult once you get you're head round it; i always try to make things complex for myself, its a bad habbit.
Makes much more sence now after reading the Recommended Articles.
Mahesh ChandPosted Dec 16, 2010, 10:02 PM
Subhendu DePosted Dec 16, 2010, 3:38 AM
Thanks.....
John BurnsPosted Dec 16, 2010, 3:35 AM
i shall sit and try working out some examples and figure out how everything fits together
Subhendu DePosted Dec 16, 2010, 3:24 AM
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.
Use a static class to contain methods that are not associated with a particular object. For example, it is a common requirement to create a set of methods that do not act on instance data and are not associated to a specific object in your code. You could use a static class to hold those methods.
The main features of a static class are:
They only contain static members.
They cannot be instantiated.
They are sealed.
They cannot contain Instance Constructors.
Creating a static class is therefore much the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.
The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.
Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.
A static method, field, property, or event is callable on a class even when no instance of the class has been created. If any instances of the class are created, they cannot be used to access the static member. Only one copy of static fields and events exists, and static methods and properties can only access static fields and static events. Static members are often used to represent data or calculations that do not change in response to object state; for instance, a math library might contain static methods for calculating sine and cosine.
Static class members are declared using the static keyword before the return type of the member.