Structure in C#

Posted on Updated on

Image result for Structure in C#Structure in C#

Structure is a value type data type in C#. With the help of structure a single variable can hold the values of different data types.To create a structure struct keyword is used.Structs can also contain constructors, constants, fields, methods, properties, indexers, operators, events and nested types.Structs cannot be declared as protected as they cann’t be inherited from another struct but they can implement an interface.
Structures are used to enhance the performance in managed environment.C# supports the notion for value types and reference types. The reference type values are stored in heap memory and when are not in use are garbage collected. In contrary instances of values types are managed in stack and that’s why the allocated memory is released as soon as there scope ends. all the refernce type are passed by reference while the values types are passed by value in the method. In C# all the data types are of value type except System.String.

Value types can be created in C# by using enum keyword and struct keyword.As the value type get stored in stack, the load on heap memory will be less, which results in lesser load on garbage collector, less frequent GC cycles, resulting in better performance. The major problem associated with struct is in passing, if it is big which is costlier than passing a reference.The other problem is related with boxing and unboxing.

public struct Foo
// Fields
private string fooString;
private int fooNumber;

// Property
public string FooString
return fooString;
fooString = value;

// Method
public int GetFooNumber()
return fooNumber;


For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.
Helpline: 9814666333, 8699444666

Please fill the form and we shall contact you soon.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s