Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# discussion: Redundant class names?
Message
De
29/07/2008 10:08:21
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01334856
Message ID:
01334866
Vues:
17
>>>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();

They are combining two commands into one. I think somebody mentioned before that it is short for (in VB):
Dim tt As Tautology

tt = New Tautology
The first line is creating the variable, and the second line is instantiating the object.
Very fitting: http://xkcd.com/386/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform