Definite Assignment and Array of struct : struct array « struct « C# / CSharp Tutorial






using System;
struct Complex
{
    public Complex(float real, float imaginary) 
    {
        this.real = real;
        this.imaginary = imaginary;
    }
    public override string ToString()
    {
        return(String.Format("({0}, {0})", real, imaginary));
    }
    
    public float    real;
    public float    imaginary;
}

class MainClass
{
    public static void Main()
    {
        Complex[]    arr = new Complex[10];
        Console.WriteLine("Element 5: {0}", arr[5]);        // legal
    }
}
Element 5: (0, 0)








6.12.struct array
6.12.1.Definite Assignment and Array of struct