Timeline for Hidden Features of C#?
Current License: CC BY-SA 2.5
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 25, 2011 at 16:17 | comment | added | AviD | @desco, I imagine this could only possibly apply to value types, and not reference types (arrays are reference types). | |
| Jul 3, 2010 at 0:56 | comment | added | desco | This approach is not uniform, for example if you try to repeat the same trick with fields of array type, i.e interpret uint[] as int[] - result shall be unverifyable. | |
| Jan 25, 2010 at 19:14 | comment | added | Ray Burns | Warning: This approach does not take into account endianness. That means your C# code will not run the same way on all machines. On little-endian CPUs (which store the least significant byte first), the behavior shown will be used. But on big-endian CPUs, the bytes will come out reversed from what you expected. Beware how you use this in production code - your code may not be portable to certain mobile devices and other hardware, and may break in non-obvious ways (eg two files ostensibly in the same format but actually with byte order reversed). | |
| Oct 16, 2009 at 23:01 | comment | added | snarf | This has its uses, mostly with binary data. I use a "Pixel" struct with an int32 @ 0, and four bytes for the four components @ 0, 1, 2, and 3. Great for manipulating image data quickly and easily. | |
| Oct 1, 2009 at 16:27 | comment | added | manixrock | The annoying thing about this is if you're going to use this is a struct the compiler will force you to set ALL the variables in the init function. So if you have: public A(int int32) { Int32 = int32; } it will throw "Field 'One' must be fully assigned before control is returned to the caller", so you have to set One = Two = Three = Four = 0; as well. | |
| Aug 5, 2009 at 17:20 | comment | added | John Leidegren | There's also meaningful to say int and float at offset 0. It's what you need if you want to manipulate floating point numbers as bit masks, which you sometimes want to. Especially if you wanna learn new things about floating point numbers. | |
| Jul 23, 2009 at 19:07 | comment | added | scottm | @George, works wonders when you are communicating with legacy apps over sockets using c union declarations. | |
| Sep 23, 2008 at 20:39 | history | answered | ZeroBugBounce | CC BY-SA 2.5 | |
| Sep 23, 2008 at 20:39 | history | made wiki | Post Made Community Wiki by CommunityBot |