Home > Backend Development > C#.Net Tutorial > In C#, what is a structure?

In C#, what is a structure?

王林
Release: 2023-08-27 18:29:02
forward
1189 people have browsed it

In C#, what is a structure?

In C#, a structure is a value type data type. It helps you to make a single variable hold related data of different data types. Use the struct keyword to create structures.

C# structures have the following characteristics:

  • Structures can have methods, fields, indexers, properties, operator methods and events.

  • A structure can have a defined constructor, but no destructor. However, you cannot define a default constructor for a structure. The default constructor is automatically defined and cannot be changed.

  • Unlike classes, structures cannot inherit other structures or classes.

  • Structures cannot be used as the basis for other structures or classes.

  • A structure can implement one or more interfaces.

Let’s see how to define a structure:

struct Student {
   public string name;
   public int id;
   public string subject;
};
Copy after login

Above we have a structure that contains student details. These details will belong to different data types, such as strings for names, integers for student IDs, and so on.

The above is the detailed content of In C#, what is a structure?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template