What's the list of new language features in Visual Basic 10.0 and C# 4.0? (Lisa Feigenbaum)

What's the list of new language features in Visual Basic 10.0 and C# 4.0? (Lisa Feigenbaum)

  • Comments 24

This post is in response to a question we received in the blog comments last week. It's often difficult to study future versions of VB and C#, and figure out what's the same and what's different! Therefore, I've put together a chart that shows both the VB 10.0 and C# 4.0 feature lists together. (VB 10.0 and C# 4.0 are the language versions that will be included in the Visual Studio 2010 release.) One thing you may notice is that the lists look very much the same! That is part of our efforts to ensure that whichever language you are using, you will have the same functionality available to tackle your development tasks.

image

 

Leave a Comment
  • Please add 1 and 5 and type the answer here:
  • Post
  • PingBack from http://www.codedstyle.com/whats-the-list-of-new-language-features-in-visual-basic-100-and-c-40-lisa-feigenbaum/

  • The "Implicit Line Continuation" makes vb not like vb ,but like C style language.

    In this case,

    How about supports to write Unsafe code?

    and we need use XNA in VB.

  • I agree to cyclone_dll, an implicit line continuation is unnecessary as it makes it not BASIC anymore and we can achieve the same thing by using the line continuation operator.

    Besides we rather need some important language extension:

    a) A lazy ternary operator. The IIf function is a pain-in-the-arse surrogate.

    b) Support for emitting the sizeof opcode, be it safe or unsafe, because sometimes I need the size of a value type.

    c) An equivalent operator for default(Type) in c# because sometimes I need the default value of a generic Type.

    d) Support for direct converting between char and integer types because calling the VB style functions is very, very slow and annoying.

    These things are, in my opinion, much more important than messing around with the language paradigms like line continuation.

  • (a) "If(b,x,y)" is the lazy ternary operator. It means "if b then x else y", and only evaluates x if b is true, and only evaluates y if b is false.

    "If(x,y)" is the coalesce operator. It means "Dim $t = x : if not $t is nothing then $t else y". It works for nullables and reference types. It only evaluates y if x is nothing.

    (c) "Nothing" is the exact equivalent for default(Type). "Dim x As IntPtr = Nothing" is the same as default(IntPtr) is the same as IntPtr.Zero. Incidentally, the null reference is the default for all reference types.

    (d) I'm curious what you mean by "very slow"? Dim x = AscW("a"c) is exactly as fast as the C# code "int x = 'a';"... they both produce the same IL.

    (b) Could you spell out for me in a little more detail, please, even if you did know the size of a value type, how would you use it in a safe manner?

  • a) x and y are evaluated, because Iff is a function, then both results are passed to the function Iff and one of them is returned. That's not what I call lazy evaluation.

    b) Maybe I want to calculate the needed memory of an array to present it to the user or to make decisions for the creation of look-up-tables.

    c) See the difference between c# and vb.net code:

    void c<t>(t h)

    {

       h = default(t);

    }

    translates to

    .method private hidebysig instance void  c<t>(!!t h) cil managed

    {

     // Code size       9 (0x9)

     .maxstack  8

     IL_0000:  ldarga.s   h

     IL_0002:  initobj    !!t

     IL_0008:  ret

    } // end of method Form1::c

    Sub c(Of t)(ByVal h As t)

       h = Nothing

    End Sub

    translates to

    .method public instance void  c<t>(!!t h) cil managed

    {

     // Code size       12 (0xc)

     .maxstack  1

     .locals init ([0] !!t VB$t_generic$S0)

     IL_0000:  ldloca.s   VB$t_generic$S0

     IL_0002:  initobj    !!t

     IL_0008:  ldloc.0

     IL_0009:  starg.s    h

     IL_000b:  ret

    } // end of method Form1::c

    d) But what about:

    Dim Val as Short

    .

    .

    Dim Val2 as Char = ChrW(Val)

    This makes a call to a function.

    In C# it's simply:

    short Val;

    .

    .

    char Val2 = (char) Val;

  • (a) "If" is the lazy operator. "IIf" (two Is) is the function.

    Give me a few days to think about the others...

  • "if" is a new operator in vb 9,it use short evaluation,and can be used like this:

    "' When the divisor is 0, IIf causes a runtime error, but If does not.

    divisor = 0

    Console.WriteLine(If(divisor <> 0, number \ divisor, 0))

    ' Console.WriteLine(IIf(divisor <> 0, number \ divisor, 0))

    ". tox ,you can see it in MSDN.

    I agree to tox,and here is additional opinions:

    a) Use "#Region .... End Region" in method block.

    b) A vb style multi-line comment like " /* .....*/" in c#.

  • Really cool post !!!

    Bye from Spain

  • Why are there so many VB6 developers although the last VB version dates back to 1998?

    Because VB .NET is far too complex! Don't introduce more language features or you never get the VB6 programmers to migrate to VB .NET.

  • Sicual,

    Thanks for your comment! My name is Daniel Walzenbach and I’m a PM on the Visual Studio team. As we’re always interested in feedback from our customers I’d like to know what you’re missing in VB.NET to like it/switch from VB6? If part of your answer is “less complex” can you qualify/quantify this? What are you missing? What would you like to see? If you don’t want to post publicly you can also write me mail at daniel.walzenbach(at)microsoft.com.

    Thanks!

      Daniel

  • An automatic way to convert VB.NET to C# and C# to VB.NET would be nice since we want to standardize on C# and migrate all of our VB.NET code to C#.

  • Hi Daniel,

    Which language should you use: C# 4.0 or VB .NET 10.0?

    If I’m looking at the posted feature list then I believe that they are equal. They have different keywords and syntax but that’s it. So we have two equal competing programming languages for .NET.

    In my opinion the languages are mostly used by:

    1. Small Basic: Hobby programmer who wants to learn the basics of software development.

    2. Visual Basic 6: Half programmer and half domain expert who wants to write small software tools that helps him and his colleagues to handle their domain more efficient.

    3. C#: Professional software developer who writes large enterprise applications, frameworks… (But often lacks of the in-depth domain knowledge)

    I see VB .NET just as a replacement for C# - same features, same power and the same complexity. In my opinion VB .NET should have been the simplified version (less features) of C# so that VB6 developers have a chance to move to the .NET Framework.

    What I do not need are language features that help me to save some lines of code but don’t give me any added value.

    * Auto-Implemented Properties: A colleague asked me recently about this C# feature: “I see that I’m able to save some lines of code but where is the value stored of the property?” Maybe this feature uses some advanced concept like the DependencyProperty. I had to look at the generated IL code (in Reflector) to understand how this feature works.

    * Implicit Line Continuation: Here I have to agree with cyclone_dll. It’s not worth to change this behavior.

    * Statement Lambdas: Great feature but I think it is understood only by highly skilled developers.

    A personal feature wish: I agree with Greg. Conversion between VB .NET and C# code would be great.

  • I can contribute with this:

       Dim i As Integer = 65

       Dim s As String = Char.ConvertFromUtf32(i)

       Dim v As Integer = Char.ConvertToUtf32(s, 0)

       Dim c As Char = Char.ConvertFromUtf32(i)(0)

    But I agree that it should be fine a Char costructor with an integer parameter and viceversa.

    I don't understand the new implicit line continuation, in the sense I don't figure how distinguish when a line is new and when it is continued, or when it is finished. I wait for the new VB, to judge.

  • * Auto-implemented properties

    Yes! It's only sugar but I like it

    * Implicit line continuation

    Could be nice but if it cost a lot in terms of development I would abandon it.

    Instead please consider another feature that C# has gained with the last release and VB.NET does not have: Anonymous Multiline Delegates

    Without this feature it is not so trivial translate a useful piece of code/class written in C# into VB.NET.

    What do you think about it? Any possibility to see in next release?

  • marco: Thanks for your feedback! The "Statement Lambdas" listed is indeed the same as C# anonymous multilne delegates.

Page 1 of 2 (24 items) 12