C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
Java
Learn iOS Programming
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
10
Reply
Can a non static class have static constructor?
Shambhu
13y
28.7k
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
how can trust
RATNESH SAHU
9y
1
Yes Normal class can have static constructor but only one. it automatically called only once when any of class member is first time called or access.. even at instance creation. And important thing is static constructor should be parameterless...
Dinesh Bhoje
12y
1
yes we can have static constructor inside a non-static class.
Anil Kumar Murmu
9y
0
Yes, it can.But user will not have any control on its invoke.
Ashish
11y
0
Yes, we can have static constructor . But user have no control over evoking it.
Ashish
11y
0
Yes, It can have.. http://msdn.microsoft.com/en-us/library/ms173116%28v=vs.80%29.aspx
Ravikumar G
12y
0
yes it is possible, Refer this link http://sandeepmhatre.blogspot.com/2013/03/constructors.html
Sandeep Mhatre
12y
0
but we can not use this value every time variable is 0
Tanuj Khurana
12y
0
yes we can create the static constructor in non static class... it is parameter less and how static constructor called only once when how many number of objects created to the that class static fields only one reference
jeevan prasad
12y
0
Yes, it is possible.
But we have to create an object of the class inside the static constructor and then initialize the non static member through the objectreference.
And to initialize static member of the class too.
class Class2
{
int a;
static Class2()
{
Class2 p = new Class2();
p.a = 45;
System.Console.WriteLine(p.a);
}
static void Main()
{
}
}
Shambhu
13y
0
Message