Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C# y u do dis to me? (C# Arrays)

Name: sadimir 2011-12-02 14:15

Switching from c++ to c# and derping hard.

The error:
"An unhandled exception of type 'System.NullReferenceException' occurred in sharp_TEST.exe

Additional information: Object reference not set to an instance of an object."

The masterpiece:

    class Program {
        static void Main() {

            Polygon4[] x = new Polygon4[20];

            foreach (Polygon4 face in x)
            {
                face.print();
            }

        }
    }
//////////////////////////////
    class Polygon4
    {
        Vertex3D a, b, c, d;
        public Polygon4()
        {
            a = new Vertex3D();
            b = new Vertex3D();
            c = new Vertex3D();
            d = new Vertex3D();

        }
        public void print()
        {
            a.print();
            b.print();
            c.print();
            d.print();

        }
    }
/////////////////////////////
    class Vertex3D
    {
        float x, y, z;
        public void print()
        {
            System.Console.Write(x+" "+y+" "+z+"\n");
        }
        public Vertex3D()
        {
            x = y = z = 0;
        }
    }

Explain c# object arrays pls

Name: sadimir 2011-12-02 16:05

I found out that all 20 of the array members are null pointers =/
Am I supposed to do something extra to initialize the members?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List