Javatpoint.com is changed to TpointTech.com
C# StructsIn C#, classes and structs are blueprints that are used to create instance of a class. Structs are used for lightweight objects such as Color, Rectangle, Point etc. Unlike class, structs in C# are value type than reference type. It is useful if you have data that is not intended to be modified after creation of struct. C# Struct ExampleLet's see a simple example of struct Rectangle which has two data members width and height. Output: Area of Rectangle is: 20 C# Struct Example: Using Constructor and MethodLet's see another example of struct where we are using constructor to initialize data and method to calculate area of rectangle. Output: Area of Rectangle is: 30 Note: Struct doesn't support inheritance. But it can implement interfaces.Next TopicC# Enum |
Javatpoint.com is now changed to TpointTech.com, so we request you to subscribe our newsletter for further updates.
The is like the normal class but it cannot be instantiated. It can have only static members. The advantage of static class is that it provides you guarantee that instance of static class cannot be created. Points to remember for contains only static members. cannot...
1 min read
In c# programming, this is a keyword that refers to the current instance of the class. There can be 3 main usage of this keyword in C#. It can be used to refer current class instance variable. It is used if field names (instance variables) and parameter...
2 min read
Enum in C# is also known as enumeration. It is used to store a set of named constants such as season, days, month, size etc. The enum constants are also known as enumerators. Enum in C# can be declared within or outside class and structs. Enum constants...
3 min read
is used to initialize static fields. It can also be used to perform any action that is to be performed only once. It is invoked automatically before first instance is created or any static member is referenced. Points to remember for C# Static Constructor cannot have...
2 min read
In C#, static is a keyword or modifier that belongs to the type not instance. So instance is not required to access the static members. In C#, static can be field, method, constructor, class, properties, operator and event. Note: Indexers and destructors cannot be static. Advantage of ...
5 min read
Since C# is an object-oriented language, program is designed using objects and classes in C#. C# Object In C#, Object is a real world entity, for example, chair, car, pen, mobile, laptop etc. In other words, object is an entity that has state and behavior. Here, state means data...
5 min read
In C#, constructor is a special method which is invoked automatically at the time of object creation. It is used to initialize the data members of new object generally. The constructor in C# has the same name as class or struct. There can be two types of...
3 min read
A destructor works opposite to constructor, It destructs the objects of classes. It can be defined only once in a class. Like constructors, it is invoked automatically. Note: C# destructor cannot have parameters. Moreover, modifiers can't be applied on destructors. C# Constructor and Destructor Example Let's see an example...
1 min read
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India