Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# discussion: Redundant class names?
Message
From
29/07/2008 14:15:26
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01334856
Message ID:
01335018
Views:
15
>>>>>This is the first in what I think will be a series of discussions relating to C#. I am immersed in learning it and know others are as well. Or already have, or are thinking about it. Generics and interfaces are a couple of topics I have in mind after I get a question that has been bugging me for a while out of my system. The answer is probably blindingly obvious to someone who already knows C#.
>>>>>
>>>>>Here is my question. When you instantiate an object, you do it like this:
>>>>>
>>>>>Circle cir = New Circle();
>>>>>
>>>>>Why does the class name occur twice? Why isn't the Circle() on the right sufficient to define the type of object being created?
>>>>>
>>>>>i.e. Why isn't it? ---
>>>>>
>>>>>cir = New Circle();
>>>>
>>>>Just a language design choice. If allowed it would be the equivalent of ' var cir = new Circle(); '
>>>>Regards,
>>>>Viv
>>>
>>>But why would they make such a design choice? It truly seems redundant to me, just extra typing.
>>>
>>>Tautology tt = New Tautology();
>>
>>Maybe the syntax was just for consistency. In some cases you might want to treat the object as a parent class or asan interface that it implements. e.g:
>>
>>ParentClass p = new ChildClass();
>
>I don't understand that at all -- instantiating a parent object based on a derived child class?

Maybe the wording of Parent/ Child is the confusion. How about this
AutoBase ab = new Compact();
The class instantiated is Compact but it is subclassed from it's base of AutoBase.
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform