C# Simplified, part 4: Structures, Inheritance and Interfaces
(Page 1 of 7 )
In this article, the fourth in a series covering C#, you will learn about structures, inheritance, and interfaces, with the help of illustrative source code. If you ever wondered what C# uses instead of multiple inheritance, keep reading.
About the C# Simplified Series
C# Simplified covers each and every concept of the C# programming language in a concise manner. The articles in this series have been divided into several parts and will provide detailed explanations along with source codes and screenshots. This series has been specifically written for beginners and students with an aim to teach C# in a quickest possible time. Please send your comments to csharpsimplified@gmail.com
If you are familiar with C++, you should be familiar with structures. Structures are value types, and are defined by using the struct keyword. You should create an object of the structure in order to access the variables inside them. In listing 4.1, a structure named EmpStruct is created with two variables. Inside the Main() method, an object of the structure is created, and the appropriate variables are called and printed.
Listing 4.1 using System;
struct EmpStruct
{
public int age;
public string id;
}
class StructDemo
{
public static void Main()
{
EmpStruct es;
es.id = "100";
es.age = 20;
Console.WriteLine(es.age);
Console.WriteLine(es.id);
}
}
Next: Properties >>
More C# Articles
More By Anand Narayanaswamy