what is struct in c# code example
Example 1: c# struct
public struct Coords
{
public Coords(double x, double y)
{
X = x;
Y = y;
}
public double X { get; }
public double Y { get; }
public override string ToString() => $"({X}, {Y})";
}
Example 2: structure in c sharp with example
struct Coordinate
{
public int x;
public int y;
}
Coordinate point = new Coordinate();
Console.WriteLine(point.x);
Console.WriteLine(point.y);
Example 3: structure in c sharp with example
class Program
{
static void Main(string[] args)
{
Coordinate point = new Coordinate();
point.CoordinatesChanged += StructEventHandler;
point.x = 10;
point.y = 20;
}
static void StructEventHandler(int point)
{
Console.WriteLine("Coordinate changed to {0}", point);
}
}