Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# discussion: Redundant class names?
Message
From
29/07/2008 10:17:15
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
29/07/2008 10:13:24
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01334856
Message ID:
01334872
Views:
13
>>>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();
>>
>>It is how C# language defined. You first declare your variable's type then do an assignment.
>>
>>
Circle cir = new Circle();
>>
>>is the easier form of:
>>
>>
Circle cir;
>>cir = new Circle();
>>
>>However in C# 3.0 there is type inference.
>>
>>
var cir = new Circle();
>>
>>IMHO it's weird from the start (C# 1.0) why you need to have type declaration when type could be inferred from constructor.
>>
>>PS: Maybe just because they couldn't think of a better way for intellisense.
>>Cetin
>
>But isn't this what strong typing is all about? Without declaring the variable type first, doesn't that imply weak typing?

No it doesn't because such strong typing is caught during compilation, not before. Could catch then. With var it's doing that at least locally. My guess they couldn't find a better way.
Strong typing is another discussion that I wouldn't get into.

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform