convert javascript function to C# (conversion question)
since i'm poor with javascript I would like someone to convert this small function to C# code for me..
var cn = 0;
function C(i,s)
{
return s.charCodeAt(i) ^ (cn|1) ^ ((cn++ & 1)?i:0) 开发者_运维技巧^ 0x55
}
I would really appreciate your help. thanks in advance :)
private static int cn = 0;
public static int C(int i, string s)
{
return s[i] ^ (cn | 1) ^ (((cn++ & 1) == 1) ? i : 0) ^ 0x55;
}
private static int cn = 0;
public static int C(int i, string s)
{
return ((byte)s[i]) ^ (cn|1) ^ ((cn++ & 1) != 0 ? i:0) ^ 0x55;
}
That's written with the assumption that the function is going into a class as a static function, so you would call it like this:
MessageBox.Show(MyType.C(0, "test")); //Output: 32
If you remove the static
keyword, you can call it as an instance method:
MyType something = new MyType();
MessageBox.Show(something.C(0, "test"); //Output: 32
精彩评论