Skip to content

Instantly share code, notes, and snippets.

@lzhoucs
Last active November 13, 2015 23:20
Show Gist options
  • Save lzhoucs/3f16bb4bc1d598fb753b to your computer and use it in GitHub Desktop.
Save lzhoucs/3f16bb4bc1d598fb753b to your computer and use it in GitHub Desktop.
The beauty of c# compared to java
  • Access modifier

protected internal can block any third party code outside of the assembly from subclassing/overriding methods inside the assembly.

  • equals

Object.ReferenceEquals() can check reference equality when hashcode()/equals() have been overriden to compare object equality between two objects. In java we can only check either object equality or reference equality, but not both.

  • package/code organization

Project(module/library) name can be directly reused as the package/namespace name to save unnecessary package declaration/creation.

  • pass by reference

c# allows program to pass variable by both value(out-parameter) and reference(in-parameter), whereas java only allows passing by value.

  • object literals

in c# an array of double can be created using literal syntax, whereas java doesn't offer these syntax.

double[] numbers = {1.1, 2.2, 3.0};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment