what is a struct c# code example
Example 1: how to make custom struct C#
struct Parts
{
public static Parts NewPart(string PartName, string strName, int PartId)
{
return new Parts
{
Part = PartName,
Name = strName,
Id = PartId
};
}
public string Part { get; set; }
public string Name { get; set; }
public string Id { get; set; }
}
Example 2: structure in c sharp with example
Book 1 title : C Programming
Book 1 author : Nuha Ali
Book 1 subject : C Programming Tutorial
Book 1 book_id : 6495407
Book 2 title : Telecom Billing
Book 2 author : Zara Ali
Book 2 subject : Telecom Billing Tutorial
Book 2 book_id : 6495700
Example 3: 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 4: 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);
}
}