Thursday, August 16, 2012

How to select distinct anonymous types in VB.NET

dim q = (from a in myList select new with {Key .Name = a.Name , Key .Age = a.age}).Distinct().ToList

Just use the Key keyword and that's it !

Thursday, August 2, 2012

The best explanation on Yield keyword for C#, VB.NET

YIELD is a new feature in VB.NET 4.5
old feature of C# (2.0)
An answer I found at stackoverflow, which I think is the best in the entire world

try this

public void Consumer()
foreach(int i in Integers())

public IEnumerable Integers()
yield return 1;
yield return 2;
yield return 4;
yield return 8;
yield return 16;
yield return 16777216;

It's changing a function into a "list that can contain execution blocks".  Meaning I can do this too

yield return GetWebService1.somefunction();
yield return getSomeDataFromDataBase();
yield return scope_variable;


I'm still thinking how I can use yield in real life, that's the challenge (in a fun way)