>>>
>>>TIA.
>>
>>
>>Dmitry,
>>
>>If the method of the class is not marked as static, you have to instantiate the class prior to calling the method
>>
>>var obj = new MyClassName();
>>obj.MethodName();
>>
>>
>>If the method of the class has been marked as static, you can call it without instantiating the class
>>
>>
>>
>>// class definition
>>public class MyClassName
>>{
>>
>>public static MethodName()
>>{
>>}
>>}
>>
>>
>>// then call like this
>>MyClassName.MethodName()
>>
>
>Thank you, Gregory. This explains what I was missing. It looks like having methods marked as static makes it easier to use them. Is there much downside to it, as far as you know?
Static methods can only use static methods and static fields - unless an object is passed as a parameter
It depends .
In a Person's class, a BirthDate would be an instance property - since it's different for each person
The method to calculate the age would not be static, since it will access the BirthDate of the instance
Sample
public class Person
public DateTime BirthDate;
public int CalcAge()
{
}
}
Gregory