Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C# "var" bad or benefits?

C#

  • Please log in to reply
31 replies to this topic

#25 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

Posted 14 September 2012 - 05:39 AM

You must have come from a VB background. Programmers with a C++ background will write IEnumerable<x> every time.
  • 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#26 lobo521

lobo521

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 68 posts

Posted 14 September 2012 - 06:13 AM

You must have come from a VB background. Programmers with a C++ background will write IEnumerable<x> every time.


In c++ you also have type inference http://mariusbancila...inference-in-c/
So i think that not all c++ programmers will use full syntax.
What with programmers with only C# background? I'm one of them and i use implicit typed variables. Sometimes type is realy nasty when i don't see the point of writing type explicitly like:
IEnumberable<IGrouping<string, string>> groups;
  • 0

#27 AceInfinity

AceInfinity

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 313 posts
  • Programming Language:C, C++, C#, Perl, Visual Basic .NET, Assembly, VBScript, Others

Posted 14 September 2012 - 08:31 PM

You must have come from a VB background. Programmers with a C++ background will write IEnumerable<x> every time.


No, I know both C# and VB.NET, but I am also a C++ programmer (for the most part C/C++), but what is the topic of this thread here? I see "C#", not "VB", although VB/VB.NET doesn't have a var keyword either... I'm not sure where you'd get that one from quite honestly. :confused:

Being too assumptious and creating your own programmer stereotypes won't get you far. Just my two cents.

~Ace
  • 0

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image


#28 PuddingEatsPanda

PuddingEatsPanda

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts
  • Programming Language:C++, C#
  • Learning:PHP, JavaScript, Bash, Others

Posted 11 November 2013 - 10:42 AM

I find var helpful especially if I get lazy lol but I do not use it too much, mostly only on minor stuff...

Wonderful coz tis automatic XD but seeing dynamic now makes me interested to using it..


  • 0

Want to learn MOAR


#29 farrell2k

farrell2k

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 169 posts

Posted 12 November 2013 - 10:30 AM

var is definitely nice, and I wish it were available in Java.  The only thing I don't like about var in a strongly typed language is when people use it in a fashion where the type is not obvious.  


public Car GetChoice() {
    return new Honda();
}

var selection = GetChoice();

 

Now I have to hunt down GetChoice() to figure out the return type of that method.   I should not have to do this in a strongly typed language.


  • 0

Averageloser.com - I used to be a programmer like you, then I took a -> in the knee. 


#30 AceInfinity

AceInfinity

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 313 posts
  • Programming Language:C, C++, C#, Perl, Visual Basic .NET, Assembly, VBScript, Others

Posted 02 May 2014 - 07:19 PM

var is definitely nice, and I wish it were available in Java.  The only thing I don't like about var in a strongly typed language is when people use it in a fashion where the type is not obvious.  


public Car GetChoice() {
    return new Honda();
}

var selection = GetChoice();

 
Now I have to hunt down GetChoice() to figure out the return type of that method.   I should not have to do this in a strongly typed language.


With intellisense, you don't have to hunt down anything, it's available at the declaration which uses the 'var' keyword..
  • 0

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image


#31 farrell2k

farrell2k

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 169 posts

Posted 05 May 2014 - 04:47 PM

;

With intellisense, you don't have to hunt down anything, it's available at the declaration which uses the 'var' keyword..

 

I forgot that .net developers can't do anything without an ide  :lol:

 

Anyway, I have changed my stance on var.  I love it now, as long as I am using visual studio.  I am using it 100% of the time, and it saves me the hassle of having to type out the type.


  • 0

Averageloser.com - I used to be a programmer like you, then I took a -> in the knee. 


#32 AceInfinity

AceInfinity

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 313 posts
  • Programming Language:C, C++, C#, Perl, Visual Basic .NET, Assembly, VBScript, Others

Posted 05 May 2014 - 05:44 PM

You can, it's just not very productive. I'll use an editor and link it to a compiler half the time I'm writing C/C++, and ocassionally VS 2013, depending on the project.
  • 0

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download