Click here to Skip to main content
15,896,726 members
Home / Discussions / C#
   

C#

 
AnswerRe: Encryption and Decryption Pin
Pixinger778-Jun-07 3:10
Pixinger778-Jun-07 3:10 
GeneralRe: Encryption and Decryption Pin
originSH8-Jun-07 3:48
originSH8-Jun-07 3:48 
AnswerRe: Encryption and Decryption Pin
Russell Jones8-Jun-07 4:39
Russell Jones8-Jun-07 4:39 
QuestionSQL Connection DialogBox Pin
ScottM18-Jun-07 2:07
ScottM18-Jun-07 2:07 
QuestionPacking a class into a byte array - would [Serializable] do the trick? Pin
Dewald8-Jun-07 2:02
Dewald8-Jun-07 2:02 
AnswerRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
AikinX8-Jun-07 2:16
AikinX8-Jun-07 2:16 
GeneralRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
Dewald8-Jun-07 2:38
Dewald8-Jun-07 2:38 
GeneralRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
AikinX8-Jun-07 3:27
AikinX8-Jun-07 3:27 
Dewald wrote:
Aha, that makes sense. So does that mean that [Serializable] would not be the proper route then?

Yes, if the array size is not critical.
If critical you have to realize you own convertion like:
<br />
    public class myClass<br />
    {<br />
        public byte myByte1;<br />
        public byte myByte2;<br />
        public ushort myUshort1;<br />
        public ushort myUshort2;<br />
<br />
        public myClass()<br />
        {<br />
<br />
        }<br />
<br />
        public static byte[] ToByteArray(myClass value)<br />
        {<br />
            byte[] result = new byte[6];<br />
<br />
            result[0] = value.myByte1;<br />
            result[1] = value.myByte2;<br />
            unchecked<br />
            {<br />
                result[2] = (byte)(value.myUshort1 / 256);<br />
                result[3] = (byte)(value.myUshort1 - result[2] * 256);<br />
                result[4] = (byte)(value.myUshort2 / 256);<br />
                result[5] = (byte)(value.myUshort2 - result[4] * 256);<br />
            }<br />
<br />
            return result;<br />
        }<br />
<br />
        public static myClass FromByteArray(byte[] array)<br />
        {<br />
            myClass result = new myClass();<br />
<br />
            result.myByte1 = array[0];<br />
            result.myByte2 = array[1];<br />
            result.myUshort1 = (ushort)(array[2] * 256 + array[3]);<br />
            result.myUshort2 = (ushort)(array[4] * 256 + array[5]);<br />
<br />
            return result;<br />
        }<br />
    }<br />

P.S. usort is 16-bit type so we need to store it into two bytes.
GeneralRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
Dewald8-Jun-07 3:37
Dewald8-Jun-07 3:37 
GeneralRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
AikinX8-Jun-07 4:08
AikinX8-Jun-07 4:08 
AnswerRe: Packing a class into a byte array - would [Serializable] do the trick? [modified] Pin
AikinX8-Jun-07 20:43
AikinX8-Jun-07 20:43 
GeneralRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
AikinX8-Jun-07 23:50
AikinX8-Jun-07 23:50 
GeneralRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
Dewald10-Jun-07 23:09
Dewald10-Jun-07 23:09 
GeneralRe: Packing a class into a byte array - would [Serializable] do the trick? Pin
AikinX11-Jun-07 0:15
AikinX11-Jun-07 0:15 
QuestionNmericUpDown - set the Value outside the range. HELP!!! Pin
julgri8-Jun-07 1:40
julgri8-Jun-07 1:40 
AnswerRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
Guffa8-Jun-07 1:46
Guffa8-Jun-07 1:46 
GeneralRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
julgri8-Jun-07 6:42
julgri8-Jun-07 6:42 
GeneralRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
Dave Kreskowiak8-Jun-07 6:47
mveDave Kreskowiak8-Jun-07 6:47 
GeneralRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
julgri8-Jun-07 6:56
julgri8-Jun-07 6:56 
GeneralRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
Dave Kreskowiak8-Jun-07 10:08
mveDave Kreskowiak8-Jun-07 10:08 
GeneralRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
julgri8-Jun-07 6:49
julgri8-Jun-07 6:49 
GeneralRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
Dave Kreskowiak8-Jun-07 6:54
mveDave Kreskowiak8-Jun-07 6:54 
GeneralRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
julgri8-Jun-07 7:03
julgri8-Jun-07 7:03 
GeneralRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
Dave Kreskowiak8-Jun-07 10:07
mveDave Kreskowiak8-Jun-07 10:07 
AnswerRe: NmericUpDown - set the Value outside the range. HELP!!! Pin
AikinX9-Jun-07 0:06
AikinX9-Jun-07 0:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.