Home > Backend Development > C#.Net Tutorial > C# program structures and members

C# program structures and members

PHPz
Release: 2023-09-02 13:05:02
forward
1262 people have browsed it

C# 程序的结构和成员

The structure is a value type data type. It helps you make a single variable hold related data of various data types. The struct keyword is used to create structures.

To define a structure, you must use the struct statement. The struct statement defines a new data type that provides multiple members to your program.

For example, you can declare a Book structure in the following way. Following are the members -

struct Books {
   public string title;
   public string author;
   public string subject;
   public int id;
};
Copy after login

Access and display these members in the structure -

Example

using System;

struct Books {
   public string title;
   public string author;
   public int id;
};

public class testStructure {
   public static void Main(string[] args) {
      Books Book1;

      Book1.title = "PHP IN 7 Days";
      Book1.author = "Jacob Dawson";
      Book1.id = 34;

      Console.WriteLine( "Book 1 title : {0}", Book1.title);
      Console.WriteLine("Book 1 author : {0}", Book1.author);
      Console.WriteLine("Book 1 book_id :{0}", Book1.id);

      Console.ReadKey();
   }
}
Copy after login

The above is the detailed content of C# program structures and members. 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