A Structure in C# is a composite data type containing many number of different data types. A Struct in C# can contain methods, constructors, fields, other structure type, properties, constants and indexers.
<modifiers> struct <struct_name>
public class Program
{
public struct St { //Could be private, internal or protected
public int val;
public String text;
}
public static void Main(string[] args)
{
//Initializing the struct
St s = new St();
//Adding values to the struct members
s.text = "Using struct";
s.val = 2;
Console.Read();
}
}
No comments:
Post a Comment