Dumbo
Dumbo

Reputation: 14122

Integer decode porting from Java to C#

I am trying to port some code from java to C#, I have faced 2 problems so far. Here is the Java code:

public static void main(String[] args)
{
    var ia = new byte[args.length];

    for (int i = 0; i < args.length; i++)
        try
        {
            ia[i] = Integer.decode(args[i]).byteValue();
        }
        catch (NumberFormatException e)
        {
        }
    System.out.
    println(Integer.toHexString(Calc(ia, ia.length)));
}

Obviously I have to change main to Main, length to Length but no idea about:

Integer.decode(args[i]).byteValue()

and

Integer.toHexString(Calc(ia, ia.length)).

Can someone tell me please what are the avilable options in .NET in these cases?!

Upvotes: 0

Views: 1083

Answers (2)

Akash KC
Akash KC

Reputation: 16310

Possible conversion code from java to c#.Net:

public static void Main(string[] args)
{
     var ia = new byte[args.Length];

     for (int i = 0; i < args.Length; i++)
     try
     {
        ia[i] = Convert.ToByte(args[i]);
     }
     catch (FormatException e)
     {
     }
   System.Console.WriteLine(String.Format("{0:X}",Calc(ia, ia.Length))); /// I assume Calc is function return something
}

Upvotes: 1

Priyank Gupta
Priyank Gupta

Reputation: 942

You can use Convert.toInt32(string) or Parse.Int32(string)

Upvotes: 0

Related Questions