Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what the point of declaring a static method in a non-static class?

Tags:

c#

The way I understand it, having a member variable declared as static in a no-static class causes that member variable to be unique no-matter the number of instances of that class.

Now, what happen to a static method declared in non-static class? And (Most importantly), what the point of declaring a static method in a non-static class?

Thanks for helping

like image 774
Richard77 Avatar asked Jul 13 '10 11:07

Richard77


2 Answers

If the method has something to do with the type but not the instance then it can be static.

DateTime.Parse and Int32.Parse are examples.

like image 58
cjk Avatar answered Oct 07 '22 06:10

cjk


It's useful for creating factory methods which are not members of any object but which need access to the internals of an object in order to initialize it.

like image 22
Ferruccio Avatar answered Oct 07 '22 07:10

Ferruccio