As all textbooks on C# will tell you, you cannot instantiate an abstract class.
I believe the keyword abstract was intended for that purpose.
So can anyone tell me why I can do something like this:

abstract class TwoDShape
{
    // some code here
}

class test
{
    static void Main()
    {
        TwoDShape shape = new TwoDShape(); // this gives an error
        TwoDShape[] shapes = new TwoDShape[4]; // this is OK
    }
}

Hi,

I'm so unskilled compared to you and I really shouldn't know things better than you :D but I think I know why, tell me please if I'm wrong!

TwoDShape[] shapes = new TwoDShape[4];

this will create the array only, but it will not instantiate the members in it, they'll be all nulls :D maybe you knew this before...

commented: Thanks :) +7

Oops! You are quite right, I had the same issue once with an array of TextBoxes.:'(
Thank you for reminding me.:)
And, he, I'm only human, so lets consider this a slip of the mind on my behalf.
Thanks.

Haha I'm so glad I could help =D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.