For Programmers: Free Programming Magazines  


Home > Archive > C# > May 2005 > Cast struct to byte









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Cast struct to byte
Aleko

2005-05-26, 3:59 pm

Hi,

I am trying to send a struct via a UdpClient class. The Send method
expects a byte array, which a struct certainly is, but I am not sure
how to write the type cast operator.

public struct SomePacket
{
public int someData;

public static explicit operator byte[]( SomePacket packet )
{
???
}
}

I'm not even sure if this is possible, since a byte array is a
reference type, and a struct is a value type.

Thanks,
-Aleko

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com