switch (data.type) {
case FSM_Type.FSM_ADV:
Advance(data.input);
break;
case FSM_Type.FSM_SET:
Set(data.state);
break;
}
Instead of this in Java:
switch (data.type) {
case FSM_ADV:
Advance(data.input);
break;
case FSM_SET:
Set(data.state);
}
Also in Java switches: the last case does not need a break, it automatically knows that being the last case, it does not need a break. This is especially annoying in C# default cases:
switch (enum) {Actually, now that I think about it, I hated leaving break statements off of default cases when I first learned Java. Maybe C# and I were meant to be.
...
default:
...
break;
}
Speaking of enums, you do not end the last element in an enum with a semicolon in C# like in Java (it can be ended with a comma, but that is optional). You also cannot have private enum constructors, or enum methods.
I keep forgetting to write string instead of String, Java habit. There does not seem to be a difference between primitives and objects in C# (update: there isn't). For instance, in Java if I wanted to change a byte to a String for a parameter passing, it would be "new Byte(b).toString()", whereas I can simply type b.toString() in C#. The same goes for ints. Also, every primitive is a struct in C#.
In Java you can place semicolons after method blocks, in C# you cannot. I also learned that a field with the get; set; blocks defined is actually called a property, and is treated differently by the CLR than a field.
I kind of miss my @Deprecated annotation from Java, whereas C# uses [Obsolete]. In addition, C# has no easy equivalent to @SuppressWarnings("unchecked"), you have to use #pragma in the actual method, and then turn it off later.
No comments:
Post a Comment