Answers for "c# struct initialization"

C#
1

c# struct initialization

public struct Point
{
    private readonly int x;
    public int X { get { return x; } }

    private readonly int y;
    public int Y { get { return y; } }

    public Point(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
}

...

Point p1 = new Point(1, 2);
Posted by: Guest on September-21-2021
4

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})";
}
Posted by: Guest on April-15-2020

C# Answers by Framework

Browse Popular Code Answers by Language