Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Keywords
Java
abstract assert break case catch class const continue default do else enum extends false final finally for
Common Datatypes
Description
Member access dot operator Method invocation operator Array element access operator Increment and decrement operators (pre and postfix) Object instantiation operator Type verification operator Explicit cast operator Addition and subtraction operators (binary). Positive and negative operators (unary) String concatenation operator Logical negation operator Conditional AND and OR operators (short-circuited evaluation) Conditional AND, OR, and XOR operators (full evaluation of operands) Bitwise complement operator Bitwise AND, OR, and XOR operators 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-equalto, and greater-than-or-equal-to operators Conditional operator Assignment operator
Development Areas
C#
abstract Debug.Assert (method) break case catch class const continue
C#
extern new null namespace private internal public return
Java
x.y f(x) a[x] ++, -new
C#
x.y f(x) a[x] ++, -new (T)x +, + ! &&, || n/a ~
Java
byte char
C#
sbyte char double float int long
Java Range
true of false -128 to 127 0 to 216 - 1 5.0 x 10- 324 to 1.7 x 10308 1.5 x 1045 to 3.4 x 1038 231 to 231-1 -263 to 263-1 -215 to 215-1 n/a n/a implementation dependent value
C# Range
true/false -128 to 127 0 to 216 - 1 5.0 x 10-324 to 1.7 x 10308 1.5 x 1045 to 3.4 x 1038 -231 to 231-1 -263 to 263-1 -2 to 215-1
15
boolean bool
short
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
short
string object
Datatype examples
Java
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";
C#
int i = 1; byte b = 1; double d = 1.1; long l = 1; short s = 1; bool found = true; char c = 'z'; string title = "Hello World";
Note: The const and goto keywords in Java have no function. The C# const and goto keywords are operational.
Description
Provides access to members in a parent class
Keyword
operator
Description
Declares an overloaded operator
Operator
default(T)
Description
Returns the default value for a type (generics) Returns the size of a type
Array examples
Java
int[] data1; int data2[];
C#
int[] data1; n/a
checked
out
Declares an output parameter (method call) Declares a covariant type parameter(generic interface)
delegate
override
Range
28-29 significant figures 0 to 255 232-1 0 to 264 -1 0 to 2 -1
16
Size(bits)
128 8 32 64 16
event
protected Declares a member that is accessible only within the class and descendant classes (different semantics from Java protected keyword)
explicit implicit in
Declares a narrowing conversion operator Declares a widening conversion operator Declares a contravariant type parameter for a generic interface
Declares a field to be readonly Declares a reference to a value type Defines a new value type
Java wrapper classes mapped to C# structs C# identifiers that should not be used as names for types, methods, or variables:
dynamic from get group into join let orderby partial select set value var where yield
Java Wrapper
Boolean Byte Character n/a Double Float Integer Long Short Void
C# Struct
Boolean Byte Char Decimal Double Float Int32 Int64 Int16 n/a
new
virtual
# C
Java
namespace Example { // Program does not have to be in Program.cs // Main method does not have to be in a public class class Program { // Main method has a capital M static void Main(string[] args) { Car myCar = new Car(); myCar.Drive(); }
// Abstract base class abstract class Vehicle { public void Drive() { // Default implementation }
// Abstract base class abstract class Vehicle { public virtual void Drive() { // Default implementation } } // Car inherits from Vehicle class Car : Vehicle { // Override default implementation public override void Drive() { Console.WriteLine("Car running"); } } }
// Car inherits from Vehicle class Car extends Vehicle { // Override default implementation public void Drive() { } System.out.println("Car running");
Interface Example
# C
interface IDateCalculator { double DaysBetween(Date from,Date to); double HoursBetween(Date from,Date to); }
Java
class DateCalculator implements IDateCalculator { public double DaysBetween(Date start,Date end) { long startTimeMs = start.getTime(); long endTimeMs = end.getTime(); long diffInMs = endTimeMs - startTimeMs; double diffInDays = diffInMs / (24 * 60 * 60 * 1000); return diffInDays; } public double HoursBetween(Date start,Date end) { long startTimeMs = start.getTime(); long endTimeMs = end.getTime(); long diffInMs = endTimeMs - startTimeMs; double diffInHours = diffInMs / (60 * 60 * 1000); return diffInHours; }
C# Switch Example
string month;
interface IDateCalculator { double DaysBetween(DateTime from,DateTime to); double HoursBetween(DateTime from,DateTime to); } class DateCalculator : IDateCalculator { public double DaysBetween(DateTime start,DateTime end) { double diffInDays = end.Subtract(start).TotalDays; return diffInDays; } public double HoursBetween(DateTime start,DateTime end) { double diffInHours = end.Subtract(start).TotalHours; return diffInHours; }
switch (month) // string variables supported { case "Jan": monthNum = 1; break; // doesnt allow fall through case "Feb": monthNum = 2; break; default: Console.WriteLine("Invalid Value"); break; }
C# Delegate/Lambda Example
class Program { delegate int Calculation(int a, int b); static void Main(string[] args) { int x = 2; int y = 3; Calculation add = (a, b) => { return a + b; };
Properties Example
class Circle { private double radiusCM; public double RadiusMeters { get { return radiusCM / 100; } set { radiusCM = value * 100; } } } class Program { static void Main(string[] args) { Circle myCircle = new Circle(); myCircle.RadiusMeters = 50; double radius = myCircle.RadiusMeters;
# C
public class Circle { Properties property; double radiusCM; public Circle() { property = new Properties(); }
Java
C# LINQ Example
using System; using System.Linq; class Program { static void Main(string[] args) { string[] names = { "John", "Jim", "Bert", var matchingNames = from n in names where n.StartsWith("J") select n; foreach (string match in matchingNames) Console.WriteLine(match); "Harry" };
public class Program { public static void main(String[]args){ Circle circ = new Circle(); circ.setRadiusMeters(50); double radius = new Double((String) circ.property.get("RadiusMeters"));