Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# discussion: Redundant class names?
Message
De
30/07/2008 01:00:42
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01334856
Message ID:
01335186
Vues:
16
How about if you have an Interface and have several different classes that implement that Interface? In your example, say you have an IShape interface, and all you care about in the particular work that you're doing is the methods and properties of the IShape interface:
IShape one = new Circle();
IShape two = new Square();

decimal area1 = one.CalculateArea(5);
decimal area2 = two.CalculateArea(5);
~~Bonnie


>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();
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform