What is the difference between struct and class c#?
Answer / Avneesh Sharma
In C#, both Struct (struct) and Class are user-defined data types. However, there are some differences:
1. By default, classes are reference types, while structs are value types.
2. Classes support inheritance with ':' operator, but structs do not. The ':' operator in structs is used for indexer declarations.
3. Classes can have a constructor, whereas structs are instantiated using the default constructor unless explicitly defined.
4. Struct fields are public by default and cannot be private or protected, while class fields can be any access modifier (public, private, protected).
| Is This Answer Correct ? | 0 Yes | 0 No |
Is it possible to have a static indexer in c#? Allowed in c#.
When a Static Constructor is called in a Class?
What is thread safe in c#?
What is sql transaction in c#?
To catch any possible exception What is the C# syntax written ?
Are private class-level variables inherited?
What is the main method?
What is the difference between directcast and ctype?
what are the bugs are faced in a project
How many types of constructor are there in c#?
Why do we use stringbuilder in c#?
What are the types of serialization?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)