Impact of Gen-AI on IT Jobs - Growth Mindset Show
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
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
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
3
Reply
What is static class in C#?
Deepak Kamboj
12y
1.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
There are certain classes that are never intended to be instantiated, such as Console, Math, Environment and Thread Pool. C# allows you to define non- insatiable classes by using the C# static keyword 2. These classes have only static members and, in fact, the classes exist simply as a way to group a set of related members together 3. This keyword can be applied only to classes, not structures (value types) because the CLR always allows value types to be instantiated and there is no way to stop or prevent this 4. The class must be derived directly from System. Object because deriving from any other base class makes no sense since inheritance applies only to objects, and you cannot create an instance of a static class 5. The class must not implement any interfaces since interface methods are callable only when using an instance of a class. 6. The class must define only static members (fields, methods, properties, and events). 7. Any instance members cause the compiler to generate an error. 8. The class cannot be used as a field, method parameter, or local variable because all of these would indicate a variable that refers to an instance, and this is not allowed. If the compiler detects any of these uses, the compiler issues an error. 9. If you compile the code above into a library (DLL) assembly and look at the result by using ILDasm.exe, you'll see what is shown in Figure . As you can see in Figure, defining aclass by using the static keyword causes the C# compiler to make the class both abstract and sealed. Furthermore, the compiler will not emit an instance constructor method into the type. Notice that there is no instance constructor (.ctor) method shown in Figure. Figure is static (sealed and abstract), the compilerwill not emit a default constructor at all into the class definition.
Ajay Gandhi
10y
0
STSTIC CLASS CHECK PROGRAME IN COMPILE TIME
Bir Singh
10y
0
Static class are the type of class whose object creation is not possible. for similar type of C#
c# interview questions
@
http://skillgun.com
Mohit Kumar
11y
0
What are methods in C#?
What are delegates in C#?
Message