|
||
|
|
#1 (permalink) |
|
Join Date: Feb 2003
Posts: 33
|
I'am do not have a question but many solution
.Ok some nice hint at first I want to tell everyone. However this is not realy needed unless you whant realy create tricky but very fast code for special use cases. Structures are realy nic, they are fast and have no overhead. A special thing that can be done with structs is: [StructLayout(LayoutKind.Explicit, Size = 2)] public struct Memory { [FieldOffset(0)] public ushort register16Bit; [FieldOffset(0)] public byte register8BitA; [FieldOffset(1)] public byte register8BitB; } Just keep in mind windows is Litte Endian so register8BitB is the higher byte of register16Bit and register8BitA is the lower byte. For multiplatform (only if the other platform is an Big Endian System). Endianess can be aked by using BitConverter.IsLittleEndian or setting one 8Bit register of the Memory structure and check the value of register16Bit. |
|
|
|
|
|
#2 (permalink) |
|
Join Date: Feb 2003
Posts: 33
|
Im back with the next tipp of the week ^^.
Instead of using huge constructs of if's like Code:
if (x == 1)
{
...
}
else if(x == 2)
{
...
}
else if (x == 3)
{
...
}
else
{
...
}
Code:
switch(x)
{
case 1:
...
break;
case 2:
...
break;
case 3:
...
break;
default:
...
break;
}
If you have an if with many or's in the condition like. Code:
if(x== 1 || x==2 || x == 3) Code:
switch(x)
{
case 1:
case 2:
case 3:
...
break;
}
Beware you can only fall through one case label to an other if ther is no code in the upper case lable. This will work. Code:
int y = 0;
switch(x)
{
case 1:
case 2:
++y;
break;
}
Code:
int y = 0;
switch(x)
{
case 1:
++y;
case 2:
++y;
break;
}
Code:
int y = 0;
switch(x)
{
case 1:
++y;
goto case 2;
case 2:
++y;
break;
}
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|