Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get file owner
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01482984
Message ID:
01482995
Views:
51
>>
>>Can I ask you about the use of the Var type there? I know that was a new feature in C# 3.0 but thought it was for occasions when the type is unknown at compile time. Given your expertise I am sure there is a good reason.
>
>No, it's just a shortcut to tell the compiler to infer the type based on the method you are calling. It's still strongly-typed and known at compile time. One of the things I thought was really dumb when I started using .NET was how redundant statements like this were:
>
>
>StringBuilder sb = new StringBuilder();
>
>
>You mean the variable is a StringBuilder - nah, no kidding?! Apparently other people thought this was silly as well and they gave us var - the compiler infers the type based on the type being created or returned by a method. OK, so they didn't give it to us for that reason, it was needed for anonymous types. But it's still a welcome addition.
>
>This is equivalent:
>
>
>var sb = new StringBuilder();
>
>
>If you don't know the type at compile time then you would use the new "dynamic" type.

Bingo, that's the one I was thinking of. Thanks to both you and Gregory for straightening me out. I am back to immersion study of C# and .NET, and boy do I need it ;-) After 9 months back working with VFP and SQL Server it seems like half of what I knew, such as it was, has flown away. It's really true what they say -- you have to use it. Book learning doesn't really burn in, at least not for me.

Definitely count me among those who thought commands of the form "StringBuilder sb = new StringBuilder()" seemed silly.
Previous
Reply
Map
View

Click here to load this message in the networking platform