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

C#

 
GeneralRe: Play MKV files in embedded media player Pin
sypack8-Jun-07 2:37
sypack8-Jun-07 2:37 
QuestionEncryption and Decryption Pin
M. J. Jaya Chitra8-Jun-07 2:15
M. J. Jaya Chitra8-Jun-07 2:15 
AnswerRe: Encryption and Decryption Pin
Sathesh Sakthivel8-Jun-07 2:19
Sathesh Sakthivel8-Jun-07 2:19 
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 
I'm looking for a way to represent an instantiated class as a byt array (and populate an instantiated class frm a byte array. I was hoping that [Serializable] would be the magic bullet but it seems I was wrong - or do I just not understand how to use [Serializable] properly?

Let's say I have:
public class myClass
{
   public byte myByte1;
   public byte myByte2;
   public ushort myUshort1;
   public ushort myUshort2;

   public myClass()
   {
      this.myByte1 = 0x01;
      this.myByte2 = 0x02;
      this.myUshort1 = 0x0304;
      this.myUshort2 = 0x0506;
   }
}


Now, if I instantiate this class with myClass myInstance = new myClass() the member variales will hold the values as defined by the constructor. I'd like to be able to view the contents of the class as an array of bytes (ie. {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}).

So I was thinking that if the class is serializable and I write the seraialized stream to a byte array (or write a byte array to the associated stream) I'd be able to pull it off, something like this:
MemoryStream memStream = new MemoryStream();
BinaryFormatter binFormatter = new BinaryFormatter();
binFormatter.Serialize(memStream, myInstance);
byte[] myBytes = memStream.ToArray();


But myBytes is 183 bytes in size (as opposed to the expected 6 bytes) once this is finished and the contents of myBytes makes no sense to me whatsoever.

Am I on completely the wrong track here or is there hope?
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 
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 

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.