theartha
asked on
How to convert java Long to c#
Hi There,
I am new to C#. But experience in Java.
How to convert java Long to c#
Java:
private Long recNumber;
recNumber = new Long(this.getCreateDate()) ;
C#:
private long recNumber;
this.recNumber = Convert.ToInt64(this.getCr eateDate() );
I got OverflowException with error Value was either too large or too small for an Int64.
Please advice.
Thanks.
I am new to C#. But experience in Java.
How to convert java Long to c#
Java:
private Long recNumber;
recNumber = new Long(this.getCreateDate())
C#:
private long recNumber;
this.recNumber = Convert.ToInt64(this.getCr
I got OverflowException with error Value was either too large or too small for an Int64.
Please advice.
Thanks.
If you're in a 32 bit OS you may need to use ToInt32 (I can't double-check right now but as a long is 32 bits on a 32 bit OS, a 64 bit long in C# will probably fail the type checking).
Also what is "getCreateDate()" ? If it's an object, it'll need to implement the IConvertible interface and define how it gets converted to an Int64.
If it's a regular 32 bit long... no conversion needed.
Also what is "getCreateDate()" ? If it's an object, it'll need to implement the IConvertible interface and define how it gets converted to an Int64.
If it's a regular 32 bit long... no conversion needed.
ASKER
I tried in C# ...
plainText i.e String doesn't contain definition for getBytes("UTF-8")
Please advice...
plainText i.e String doesn't contain definition for getBytes("UTF-8")
Please advice...
What's the return type of this.getCreateDate()?
ASKER
@Kelaros:
I got the same error when I use Int32. getCreateDate() is a String of 80 characters in length.
I got the same error when I use Int32. getCreateDate() is a String of 80 characters in length.
ASKER
@wdosanjos:
this.getCreateDate() returns a String
this.getCreateDate() returns a String
Please provide some sample values returned by this.getCreateDate().
I think the Java and the C# versions of this.getCreateDate() are returning different values, because the Java's new Long(this.getCreateDate()) would throw a NumberFormatException exception if the value returned by this.getCreateDate() is not a long.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This solution works for me....
MessageDigest md = null;
md = MessageDigest.getInstance(
md.update(plaintext.getByt
byte raw[] = md.digest();
String hash = (new BASE64Encoder()).encode(ra
return hash;
}