Posted on Updated on

bnjh6j5h6g5jghC# STRUTURES


In C, C++ programming, you have heard about the concepts names as structures and unions. Structures are used to represent any entity like a book, table having its various attributes. For.e.
g. you are keen to store the information about a book then what data type you will prefer?

Now as book contains various information like price, pages, name of the book. But one thing hereto be notify is that these all information belong to different types like pages are of integer type as none of the page can’t be half.
Similarly price can be of float type as price can be without point notation also. Same for the name of the book that will be a group of characters i.e. known as string in programming.

So to store such various kind of information in one variable is not feasible until or unless structures came into the picture. As one variable can hold information only about one single entity. In case of Arrays they are used to store the value of the variables with the same type.

So Programmers introduced a new concept named as structures that are used to represent such entities.

You have officially utilized a straightforward structure named Books. Structures in C# are entirely not the same as that in customary C or C++.

The C# structures have the accompanying elements:

Structures can have techniques, fields, indexers, properties, administrator systems, and occasions.

Structures can have characterized constructors, however not destructors. On the other hand, you can’t characterize a default constructor for a structure. The default constructor is naturally characterized and can’t be changed.

Dissimilar to classes, structures can’t acquire different structures or classes.

Structures can’t be utilized as a base for different structures or classes.

A structure can execute one or more interfaces.

Structure individuals can’t be indicated as conceptual, virtual, or ensured.

When you make a struct article utilizing the New administrator, it gets made and the proper constructor is called. Not at all like classes, structs can be instantiated without utilizing the New administrator.

In the event that the New administrator is not utilized, the fields stay unassigned and the article can’t be utilized until every one of the fields are instated.

Declaration of Structure


Syntax for creating the structures is as same as you declared in C, C++ programming. You have to use a struct keyword to create a structure

Struct < structure name >


Elements of the structure


Example: Let us suppose we want to create a structure for a table for holding the information about the table like its number of legs, color, size, width, type.

Struct table


int legs;

char color[50];

int size;

float width;


How to access the elements of the structure Now you must remember that we can access the variable or can give the value or retrieve the value of the variable using its name. Like:

a=10; //Initializing variable value to 10

Similarly, in case of structures you can access the value of the variable but not directly you have to create an object of the structure type as:

< Struct name > < variable name1 >, < variable name 2 >……


For example now you want to provide the value to the variable of the structure table then you must have to declare the object of the structure:

Table t1, t2;

To access the elements of the structure now you can use dot operator:



This is a very simple way to create a structure and use the structure.

But one point to be remember here that you have to use public access sprecifier before all the members of the structure to access it outside the structures.


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