Dear All,
We all know static condtructors in C# are used to initialize the static data members within a class.
But it cannot be overloaded.
My question is that why this feature is not supported?
My understanding::
Is it just because that we cannot associate an object with the static constructor like the way we do it in case of non static ones by explicitly calling them while crating an instance of the class. See the following
ClassEmployee objClassEmployee = new objClassEmployee("Emp001","Upamanyu",30000); // explicitly calling the overloaded contrcutor
But we cannot do like that
StaticCons();
StaticCons(("Emp001","Upamanyu",30000); // we do not call static construtors, it gets called before the first instance of the class gets referenced.
So the overloaded feature is off in case of static ones???
Please provide your views on it.
Many Thanks,
Upamanyu
Loading

VulpesPosted Feb 24, 2013, 10:24 AM
http://www.amazon.com/CLR-via-Microsoft-Developer-Reference/sim/0735667454/2?o=18&po=9
Static constructors certainly have their problems such as deciding which one is called first when they include code which calls members of another class.
It's also not a good idea to put too much code into them as this can create a noticeable delay when accessing a member of the containing class for the first time.
Upamanyu Roy ChoudhuryPosted Feb 23, 2013, 2:25 PM
Upamanyu Roy ChoudhuryPosted Feb 23, 2013, 2:21 PM
I can get your point but where can we find what are going on behind the scene.
It is true that everything we cannot know by doing RND but atleast I am trying to get some in depth knowledge about the internals.
VulpesPosted Feb 13, 2013, 5:26 AM
Upamanyu Roy ChoudhuryPosted Feb 13, 2013, 4:07 AM
We can call a static method like this
ClassName.StaticMethod
Then why not constructors?? Why MS has not given this fecility???
VulpesPosted Feb 11, 2013, 7:11 PM
Consequently, it makes no sense for it to take any parameters as the system would have no way of knowing what arguments to pass for those parameters.
As it can't take any parameters, it follows that it can't be overloaded either.