C# for Java Developers. Keywords. Operators. Common Datatypes.
Development Areas. C# Features Not Available in Java 6. LINQ. Delegates.
Events.
# C
for Java Developers
Keywords Java
C#
Java
C#
abstract
abstract
native
extern
assert
Debug.Assert (method) break case catch class const continue
new
new
null package private protected public return
null namespace private internal public return
break case catch class const continue default do else enum extends false final finally for
goto if implements import instanceof interface
default do else enum : false sealed finally for / foreach goto if : using is interface
static strictfp super switch synchronized this throw throws transient true try … (varargs) void volatile while
static n/a base switch lock this throw n/a [Nonserialized] (attribute) true try params void volatile while
Note: The const and goto keywords in Java have no function. The C# const and goto keywords are operational.
Java
C#
Description
x.y
x.y
Java
Member access “dot” operator
boolean bool
f(x) a[x]
++, --
C# keywords not found in Java, or with different behavior Keyword
Description
Keyword
Description
base
Provides access to
operator
Declares an overloaded
members in a parent Enables arithmetic overflow checking
new
Declares an event
Increment and decrement operators (pre and post-
new
(T)x +, -
float
Object instantiation operator
int
Type verification operator
(T)x
long
Explicit cast operator
+, -
Addition and subtraction operators (binary). Positive and negative operators (unary)
+ !
&&, ||
+
String concatenation operator
!
Logical negation operator
&&, ||
Declares a widening
&, |, ^
n/a
Conditional AND, OR, and XOR operators (full evaluation of operands)
~
&, |, ^ >>>
*, /, % ==, !=
, = x?y:z
~
Bitwise complement operator
&, |, ^
Bitwise AND, OR, and XOR operators
n/a
Signed left-shift and right-shift operators
>>
Unsigned right-shift operator
*, /, %
Multiply, divide, and modulus operators
==, !=
Is-equal-to and is-not-equal-to operators
, =
Relational less-than, greater-than, less-than-or-equal-
x?y:z
Conditional operator
to, and greater-than-or-equal-to operators
=
Assignment operator
in
Declares a
that hides a method in a base class (method modifier)
231 to 231-1
-231 to 231-1
-263 to 263-1
-263 to 263-1
-215 to 215-1
-2 to 215-1
n/a
n/a
n/a
n/a
int
long
short
string object
9999
value
Datatype examples Java
C#
int i = 1; byte b = 1; double d = 1.1; long l = 1; short s = 1;
int i = 1; byte b = 1; double d = 1.1; long l = 1; short s = 1;
boolean found = true; char c = 'z'; String title = "Hello World";
bool found = true; char c = 'z'; string title = "Hello World";
operator Unsigned left-shift
sizeof(T)
compound assignment Null-coalescing operator
Returns the size of a
int data2[];
Properties Indexers
n/a
Lambda Expressions
type stackalloc
Allocates a block of memory on the stack
=>
Lambda expression
typeof(e)
operator as checked
Returns the type of an
Partial Classes
Enables arithmetic
unchecked unsafe
C# datatypes not provided as part of Java
Dynamic Runtime Language
Type
Range
Size(bits)
Structures
Disables arithmetic
decimal
28-29 significant figures
128
Operator Overloading
overflow checking
byte
0 to 255
8
Enables unsafe code
uint
232-1
32
ulong
0 to 264 -1
64
ushort
0 to 2 -1
16
expression
Safe casting operator
LINQ Events
Array examples
operator ??
C# Features Not Available in Java 6 Delegates
Declares an output
Declares a method that
1st Jan 0001 to 31st Dec
implementation dependent