- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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(); } }
Advertisements