Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# int to byte Array

int number;
byte[] bytes = BitConverter.GetBytes(number);
if (BitConverter.IsLittleEndian)
    Array.Reverse(bytes);
Comment

c# class to byte array

// Convert an object to a byte array
private byte[] ObjectToByteArray(Object obj)
{
    if(obj == null)
        return null;

    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, obj);

    return ms.ToArray();
}

// Convert a byte array to an Object
private Object ByteArrayToObject(byte[] arrBytes)
{
    MemoryStream memStream = new MemoryStream();
    BinaryFormatter binForm = new BinaryFormatter();
    memStream.Write(arrBytes, 0, arrBytes.Length);
    memStream.Seek(0, SeekOrigin.Begin);
    Object obj = (Object) binForm.Deserialize(memStream);

    return obj;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: contains with ignore case c# 
Csharp :: loadscene unity 
Csharp :: C# unity link button 
Csharp :: unity text display int 
Csharp :: unity conditional field 
Csharp :: unity list of gameobjects 
Csharp :: disable script in unity 
Csharp :: {} is this used for code blcoks in c# 
Csharp :: addding two numebrs with c# 
Csharp :: wpf load file content 
Csharp :: check c# date for 0001/01/01 
Csharp :: byte to stream c# 
Csharp :: unity c# addition class 
Csharp :: print unity 
Csharp :: getset c# 
Csharp :: how to change scenes in unity 
Csharp :: Codewars Multiply 
Csharp :: get the current directory in unity 
Csharp :: unity agent does not move 
Csharp :: C++ in C# 
Csharp :: unity c# check if multiple keys are pressed 
Csharp :: how is c# pronounced 
Csharp :: emboss button in android app 
Csharp :: Unity asset storre download forlder 
Csharp :: readonly vs const c# 
Csharp :: inline list in c# 
Csharp :: how to freeze x and y position in rb2d with code unity 
Csharp :: abril modal boostrap 
Csharp :: c# entity framework code first connection string 
Csharp :: c# error CS0515 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =