Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have below code
C#
/////////////////////////////////////// 
byte[] bytestring= somefunction(); 
//somefunction() return a byte array..
 string st1 =  Encoding.UTF32.GetString(bytestring);
 byte[] bytestring2 = Encoding.UTF32.GetBytes(st1);
 bool st =  bytestring2.Equals(bytestring);

// RESULT IS st = false  
// Desired result st = true
///////////////////////////////////////////////////

I getting st = false, But I think it should be true...
what is the problem in ablove code I tried UTF8 , UnicodeEncoding .but result is same.
If bytestring2 has encoded value then how decode it( how get my old value)...

Thanks in Advance
Hemant Singh[^]
Posted
Updated 27-Dec-12 3:07am
v5
Comments
Thomas Daniels 27-Dec-12 8:09am    
What's the error?
Hemant Singh Rautela 27-Dec-12 9:00am    
the boolean variable st value is false.
But i think it should be true....

Hi,

String.Equals don't have any overload on byte array, when you pass byte array to equals function that treated as object, so no compilation error occur but it's returns false.

:)
 
Share this answer
 
Comments
Hemant Singh Rautela 27-Dec-12 12:53pm    
It is not String.Equals

bytestring2 and bytestring both are byte array.

It is object.Equals(object) method.
Suvabrata Roy 27-Dec-12 23:56pm    
Then Check your SomeFunction(), it returning properly or not
You must exactly know what is going on under the hood in method
byte[] bytestring= somefunction(); 


For exampple what is it converted fron a specific text encoding to byte array,
and what i have seen, you just try to convert it bytes with UTF encoding , and check thei equality
 
Share this answer
 
Comments
Hemant Singh Rautela 27-Dec-12 12:56pm    
somefunction() returns a byte array, it is implementd for RSA algorithm
Oleksandr Kulchytskyi 27-Dec-12 14:24pm    
I saw that somefuc returns a bytes array , that is all what i know.
But what exact it does? which encodings , and so on??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900