
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Structure and Members of the C# Program
A structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure.
To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program.
For example, here is the way you can declare the Book structure. The following are the members −
struct Books { public string title; public string author; public string subject; public int id; };
To access and display these members in a 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(); } }
- Related Articles
- Structure and Members of the Java Program
- Write a C program to display the size and offset of structure members
- Locate unused structures and structure-members
- Flexible Array Members in a structure in C
- Declaring a structure with no members in C language
- How to pass the individual members as arguments to function using structure elements?
- How to pass individual members of structure as arguments to function in C language?
- C++ program to find sequence of indices of the team members
- C++ Program to Access private members of a class
- C++ Program Structure
- Java Program Structure
- Program memory structure of Intel 8051
- What is the basic structure of a C# program?
- Explain the basic structure of a program in Java?
- Difference between Structure and Union in C Program

Advertisements