Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Use of 'var' in C#
Message
De
01/05/2010 09:18:43
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01462533
Message ID:
01462635
Vues:
48
>>>>>>What's the benefit of
>>>>>>
>>>>>>
>>>>>>var customer = new Customer();
>>>>>>
>>>>>>
>>>>>>as opposed to
>>>>>>
>>>>>>
>>>>>>Customer customer = new Customer();
>>>>>>
>>>>>
>>>>>Most of the time the type can be inferred from the right side. In those cases var is a keyword meaning the inferred type. One big advantage is that if sometimes you are unsure about the type (but it can be inferred) then you use "var" then hover your cursor on var to see the inferred type. You are free to type the type yourself or let it be inferred.
>>>>>Cetin
>>>>
>>>>I read an article in MSDN Magazine the other day about the new version of VB. There is a ton of stuff like that, not only type inference but elimination of some minor annoyances like always having to use continuation characters. The author, who is on the VB team at Microsoft, said they listened to their customers who have been asking them to let the compiler "just figure it out."
>>>
>>>Yes they are listening to:) I am hoping even one day the editor might come up to LinqPad's level
>>>(For Example type dtnrea to get to DataTableNewRowEventArgs or select and execute selection).
>>
<?xml version="1.0" encoding="utf-8" ?>
>><CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
>>  <CodeSnippet Format="1.0.0">
>>    <Header>
>>      <Title>dtnrea</Title>
>>      <Shortcut>dtnrea</Shortcut>
>>      <Description>Code snippet for DataTableNewRowEventArgs</Description>
>>      <Author>Viv</Author>
>>      <SnippetTypes>
>>        <SnippetType>Expansion</SnippetType>
>>      </SnippetTypes>
>>    </Header>
>>    <Snippet>
>>      <Code Language="csharp">
>>        <![CDATA[DataTableNewRowEventArgs]]>
>>      </Code>
>>    </Snippet>
>>  </CodeSnippet>
>></CodeSnippets>
(g)
>
>Slick.
>
>How did you produce that snippet? Not typing out XML, I hope.

Nah. I used a snippet (vbg)
TBH, I don't use them a lot - I just cut and pasted the XAML from a similar construct and changed the content. Took all of two mins....
If you're interested there is source code for a snippet editor here :http://snippy.codeplex.com/releases/view/9316
AFAICS it's pretty basic but it does work....

>I am looking forward to VS 2010 and having a chance to get busy with it. Looks like it will be a few more weeks. For some reason I couldn't get the download from the MSDN subscriber site to work, and the DVD won't ship until June sometime. (I am sure the download problem is on my PC, not a general one. There is something screwed up in my MSI configuration that causes problems with many downloaded installs. It's a rainy day project to figure that one out).

I only just realized that the MSDN shipments are now quarterly rather than monthly (didn't notice a 66% reduction in subscription rates tho). I'm still using the VS2010 beta.
Oh - and I've (literally) got a rainy day here if you want to borrow it.....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform