tags:

views:

251

answers:

1

I have a type lets call it "MyType". I have a List(Of MyType). Here is what i'm doing:

MyList.Sum(Function(x) x.MyFieldToTotal)

"MyFieldToTotal" is a decimal. For the life of me i can't figure out why x above is an object rather than a type of "MyType". Shouldn't Type Inferencing be working in this case? Even in intellisense i get "selector as System.Func(Of MyType) as Decimal"

To test the differences between C# & vb.net i did the following:

dim MyVar as new list(Of System.IO.FileStream)
MyVar.Sum(Function(x) x.

List<System.IO.FileStream> MyVar = new List<System.IO.FileStream>();
MyVar.Sum(x=>x.

In VB.Net x was of type Object while in C# x was of type FileStream. So why is type inferecing working in this case with c# and not vb.net?

Also, note that "Option Infer" is ON

+1  A: 

The type inference works at the compiler level, but it seems the intellisense engine is not picking it up (just tried in VS2008).

After you complete the statement, VS does recognize it as a FileStream object (see the tooltip)...

    Dim MyList = New List(Of System.IO.FileStream)()
    Dim result = MyList.Sum(Function(x) x.Length)

EDIT: it's a bug in VS2008 only; fixed in VS2010 RC

jeroenh
Yep your right. Seems like a VS 2008 bug. Surprised its something that a lot of people haven't run into. Very surprised. I thought maybe it was because i was using resharper but looks like thats not it.
What sucks about this really is you don't get intellisense.
@user127954 it's fixed in VS2010
jeroenh