Here is an example of a struct type coded in C#:
public struct SPoint
{
private int iX;
private int iY;
public SPoint(int pX, int pY)
{
iX = pX;
iY = pY;
}
public override string ToString()
{
return iX + ":" + iY;
}
}
Here is a method that uses this struct type:
using System;
public class SPointTest
{
public static void Main()
{
SPoint tSPoint = new SPoint(100, 200);
Console.WriteLine(tSPoint);
SPoint tAnotherSPoint = tSPoint;
Console.WriteLine(tAnotherSPoint);
}
}
In C#, each primitive type is just an alias for a struct type.
| size | C# | |
| System.Boolean | 8 | bool |
| System.Byte | 8 | byte |
| System.Int16 | 16 | short |
| System.Int32 | 32 | int |
| System.Int64 | 64 | long |
| System.Single | 32 | float |
| System.Double | 64 | double |
| System.Char | 16 | char |
| System.Decimal | 128 | decimal |