需要将vb代码转换为c# [英] Need to convert vb code to c#
问题描述
我向这个门户网站寻求帮助,因为我不知道如何在C#中转换这行Visual Basic代码,即使在一段时间后也会返回一个随机数来尝试这样做。
这是我的vb代码:
private int Random_number(int min,int max)
{
return (int)(转换。 Int((max - min + 1 )* VBMath.Rnd())+ min);
}
我试试这个:
< pre lang =cs> private int Random_number( int min, int max)
{
int seed = DateTime .Now.Millisecond;
随机rnd = 新随机(种子);
return rnd.Next(min,max);
}
但它不起作用,我不知道为什么。任何人都可以帮助它。
P.S.有人在数独中有任何Tabu搜索实现或任何参考。
感谢有利。
Just Do it:
private int Random_number( int min, int max)
{
Random rndCell = new Random(( int )DateTime.Now.Millisecond);
return rndCell.Next(min,max);
}
使用此,
http://www.developerfusion.com/tools/convert/vb-to-csharp/ [ ^ ]
你每次需要翻译时都不应该提问。以下是几个更好的可能性:
- 使用在线翻译之一。我不想指出任何一个人;请看这里: http://bit.ly/XFdX2G [ ^ ]。
请注意:不要称之为VB.NET,VB。那些是非常不同的语言;谷歌可能会受到冒犯: - )。- 现在,这是一个非常棒的离线解决方案:使用开源的ILSpy:
http://www.ilspy.net/ [ ^ ],
http://en.wikipedia.org/wiki/.NET_Reflector [ ^ ]。
首先,您需要编译项目并获得已编译的程序集。它编译为CIL:
http://en.wikipedia.org/wiki/Common_Intermediate_Language [ ^ ]。
您可以将程序集加载到ILSpy中并对其进行反汇编。它有输出语言选项。选择C#或VB.NET,然后重新编译所需的部分代码。你已经完成了。
祝你好运,
-SA
I asked for help I this portal because I don''t know how to convert this line of Visual Basic code in C# that returns a random number even after some time to try to do this.
This I the vb Code:
private int Random_number(int min, int max)
{
return (int)(Conversion.Int((max - min + 1) * VBMath.Rnd()) + min);
}
I have try this:
private int Random_number(int min, int max)
{
int seed = DateTime.Now.Millisecond;
Random rnd = new Random(seed);
return rnd.Next(min, max);
}
but it don''t works, and I don''t know why. Can anyone help with it.
P.S. Did somebody have any Tabu Search implementation in Sudoku or any reference for it.
Thanks in advantage.
Just Do it:
private int Random_number(int min, int max) { Random rndCell = new Random((int)DateTime.Now.Millisecond); return rndCell.Next(min, max); }
Use this,
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
You should not ask questions every time you need such translations. Here are a couple of much better possibilities:
- Use one of on-line translators. I don''t want to point to any particular one; just look here: http://bit.ly/XFdX2G[^].
Try to be careful: don''t call "VB.NET", "VB". Those are very different languages; and Google can get offended :-).- Now, a really wonderful off-line solution: use open-source ILSpy:
http://www.ilspy.net/[^],
http://en.wikipedia.org/wiki/.NET_Reflector[^].
First, you need to compile the project and obtain a compiled assembly. It is compiled to CIL:
http://en.wikipedia.org/wiki/Common_Intermediate_Language[^].
You can load assembly into ILSpy and disassemble it. It has the option for output language. Select either C# or VB.NET, and recompile the part of code you need. You are done.
Good luck,
—SA
这篇关于需要将vb代码转换为c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!