"beforeFieldInit"
"beforeFieldInit" is a special flag marked by compiler to the types which doesn't have static constructor.
This special flag tells "calling a static method does not force the system to initialize the type." Means that calling a static method does not make sure the static variables are initialized in the type.
public class ResourceClass
{
private static StreamWriter sw = new StreamWriter();
public static StreamWriter GetInstance()
{
return sw;
}
}
In the above type it is not guranteed that when you call GetInstance the static variable "sw" would be created. Because of the reason the class is marked as "beforeFieldInit".
public class ResourceClass
{
private static StreamWriter sw = new StreamWriter();
{
private static StreamWriter sw = new StreamWriter();
static ResourceClass() { };
public static StreamWriter GetInstance()
{
return sw;
}
}
In the above type it is guranteed that when you call GetInstance the static variable "sw" would be created. Because of the reason the class contains "static constructor".
public static StreamWriter GetInstance()
{
return sw;
}
}
In the above type it is guranteed that when you call GetInstance the static variable "sw" would be created. Because of the reason the class contains "static constructor".
Properties of static constructor
- Static constructors are not inherited, and cannot be called directly.
The exact timing of static constructor execution is implementation-dependent, but is subject to the following rules:
- The static constructor for a class executes before any instance of the class is created.
- The static constructor for a class executes before any of the static members for the class are referenced.
- The static constructor for a class executes after the static field initializers (if any) for the class. The static constructor for a class executes, at most, one time during a single program instantiation.
- The order of execution between two static constructors of two different classes is not specified.
But CLI does insist that all of the field variables will be initialized as soon as one of the static fields is accessed. So if we are depending on some side effects based on static variable initialization, then we may be waiting for a long time that to happen.
19 Comments:
Nice Food for thought!
Can you tell me a real time scenario where this can be used?
It's a important sites for contents and different kinds of information of the course in the blogs. Thanks for sharing.
hadoop training
Superb i really enjoyed very much with this article here. Really its a amazing article i had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your updation.
Digital
Marketing Company in Chennai
The given information was very excellent & Great tips, and awesome way to get exert tips from everyone, not only i like that post all peoples like that post, because of all given information was wonderful and it's very helpful for me.
IELTS Coaching in Chennai | IELTS Training in Chennai | IELTS Coaching Centre in Chennai
Really superb!!! I read your blog regularly and your content is truly good. I thank you for your effective and useful post.
IELTS coaching in Chennai
IELTS coaching centre in Chennai
IELTS Training in Chennai
Best IELTS coaching in Chennai
Best IELTS coaching centres in Chennai
IELTS classes in Chennai
Amazing blog you have given and you made a great work.surely i would look into this insight and i hope it will help me to clear my
points.please share more informations.
Loadrunner Training in Chennai
French Classes in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Android Training in Chennai
Digital Marketing Course in Chennai
JAVA Training in Chennai
German Classes in Chennai
Selenium Training in Chennai
Selenium Training in Tnagar
i read the above notes and clarify my doubts very well.in this information i observe lot of things about how to study.thanks a lot.
UiPath Training in Chennai
UiPath Training Institutes in Chennai
RPA Training in Chennai
RPA course in Chennai
Blue Prism Training Chennai
UiPath Training in Anna nagar
UiPath Training in T Nagar
the above blog is easy to clear ideas.the ideas you mentioned is super.thanks for giving ideas.
Data Science Course in Chennai
Data Science Training in Chennai
Machine Learning Course in Chennai
Machine Learning Training in Chennai
Azure Training in Chennai
Data Science Training in Velachery
Data Science Training in Tambaram
the blog helps to my research.this blog is related to my technology.thank you for the important blog.
Hibernate Training in Chennai
Spring Training in Chennai
Spring and Hibernate Training in Chennai
Struts Training in Chennai
Hibernate Training in Anna Nagar
Hibernate Training in T Nagar
Hibernate Training in Adyar
i was fully study this article and get more ideas from this article and in this article i know what to do to improve my skills..really thanks for the information.
DevOps course in Chennai
Data Science Training in OMR
Data Science Training in Porur
2 of 65
comment
Tuhin Pabna
Attachments
Nov 28, 2019, 9:29 AM
to noyon0461
2 Attachments
keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
digital marketing training in bangalore / https://www.excelr.com/digital-marketing-training-in-bangalore
Here is the details of best colleges in Bangalore. If you are looking to study in Bangalore, the below will help you to find the best colleges in Bangalore.
BSc Medical Imaging Technology Colleges in Bangalore | Medical Imaging Technology Colleges in Bangalore | BSc Optometry Colleges in Bangalore | Optometry Colleges in Bangalore |BSc Renal Dialysis Colleges in Bangalore | Renal Dialysis Technology Colleges in Bangalore |BSc Respiratory Care Technology Colleges in Bangalore | Respiratory Care Colleges in Bangalore |BSc Cardiac Care Technology Colleges in Bangalore | Cardiac Care Colleges in Bangalore |BSc Perfusion Technology Colleges in Bangalore | Perfusion Technology Colleges in Bangalore |
This was really one of my favorite website. Please keep on posting. ExcelR Digital Marketing Classes in Pune
Wow What A Nice And Great Article, Thank You So Much for Giving Us Such a Nice & Helpful Information about Java, keep sending us such informative articles I visit your website on a regular basis.Please refer below if you are looking for best Training Center.
Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
Android Training Institute in Chennai | Android Training Institute in anna nagar | Android Training Institute in omr | Android Training Institute in porur | Android Training Institute in tambaram | Android Training Institute in velachery
Are you Looking for an top Digital Marketing Services in North Carolina So hurry up we have best offers for you :)
This is really fascinating, You’re an overly skilled blogger.
I’ve joined your feed and sit up for in quest of more of your great post.
Java Training in Chennai
Java Course in Chennai
Dr Chirag j Shah Doctor for Circumcision Surgery in Ahmedabad, Gujarat, Satellite- Searching for Circumcision Surgery in Ahmedabad, Gujarat? Arham Surgical Hospital is the best Circumcision Surgery in Ahmedabad, satellite
best hearing aid provider in ahmedabad
buy best hearing aid in ahmedabad
Post a Comment
<< Home