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");
Asked
Active
Viewed 155 times
-1
user203687
- 6,473
- 12
- 48
- 81
-
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
-
1Before 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 Answers
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
- 14,876
- 2
- 42
- 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
- 957
- 6
- 18
-
This was generated using the tool: http://www.developerfusion.com/tools/convert/csharp-to-vb/ – ChickenMilkBomb Dec 09 '10 at 22:27
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
- 703,665
- 143
- 1,211
- 1,438
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,583
- 3
- 21
- 17
1