Struct in .Net:-
1.) Struct are value types.
2.) Struct in .Net are sealed i.e. they cannot be inherited.
3.) The members of a Struct are by default private and not public.
4.) Struct can have Main method also just like a class.
5.) Struct can even have a constructor but Struct can only have parametrized constructors. In early days Struct had default constructors but they were re-moved due to some reasons known only to creators ?
public struct MyStruct
{
int a;
public int b;
public MyStruct(int i, int j)
{
this.a = i;
this.b = j;
}
public void foo()
{
Console.WriteLine("Hi");
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}