-1
Int32 number = new Random().Next();
Console.WriteLine(number);

Func<Int32> GenerateRandom = delegate() { return new Random().Next(); };

Console.WriteLine("Begin Call");
GenerateRandom.DoAsync(number => Console.WriteLine(number));
Console.WriteLine("End Call"); 
user203687
  • 6,875
  • 12
  • 53
  • 85
  • Are you just trying to convert the c# code to vb.net code? – Jason Down Dec 09 '10 at 22:26
  • Just compile it in a language you know then use Reflector to view it in whatever language you want. – David Dec 09 '10 at 22:27
  • 1
    Before you spend too much translating: [Why is Random giving the same results every time?](http://stackoverflow.com/questions/767999/random-number-generator-not-working-the-way-i-had-planned-c) – dtb Dec 09 '10 at 22:27
  • There seems to be a battle of the code converters going on here. – Jeff the Bear Dec 09 '10 at 22:32
  • Hmm, I wonder what the typical automated converters come up with for that. Function lamdas were already supported in VS2008, takes some smarts to convert an anonymous method though. – Hans Passant Dec 09 '10 at 22:32

5 Answers5

2
Dim number As Int32 = New Random().[Next]()
Console.WriteLine(number)

Dim GenerateRandom As Func(Of Int32) = Function() New Random().[Next]()

Console.WriteLine("Begin Call")
GenerateRandom.DoAsync(Function(number) Console.WriteLine(number))
Console.WriteLine("End Call")
msarchet
  • 15,104
  • 2
  • 43
  • 66
2
Dim number As Int32 = New Random().[Next]()
Console.WriteLine(number)

Dim GenerateRandom As Func(Of Int32) = Function() New Random().[Next]()

Console.WriteLine("Begin Call")
GenerateRandom.DoAsync(Function(number) Console.WriteLine(number))
Console.WriteLine("End Call")
ChickenMilkBomb
  • 939
  • 6
  • 18
2

Heres' a translation.

Dim random = New Random()
Dim number = random.Next()
Console.WriteLine(number)

Dim GenerateRandom = Function ()
    Dim random = New Random()
    Dim number = random.Next()
  End Function

Console.WriteLine("Begin Call")
GenerateRandom.DoAsync(Sub (number) Console.WriteLine(number))
Console.WriteLine("End Call")
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
2

Here's a quick code conversion from http://converter.telerik.com/. I tested it and it seems to work.

Dim number As Int32 = New Random().[Next]()
Console.WriteLine(number)

Dim GenerateRandom As Func(Of Int32) = Function() New Random().[Next]()

Console.WriteLine("Begin Call")
GenerateRandom.DoAsync(Function(number) Console.WriteLine(number))
Console.WriteLine("End Call")
Jeff the Bear
  • 5,603
  • 3
  • 22
  • 18
1

Reflector is an easy and free way to convert between .NET languages.

benjy
  • 4,664
  • 7
  • 38
  • 43