This is a very brief introduction on how to use C# for developers familiar with Java.  The other resources I have found on the internet are reference-style and very long or feel too academic.  This is for people who want a very quick start into using C# and are planning to learn the full language as they go.  I hope it helps!If you actually are looking for a more complete reference, I recommend Dare Obasanjo’s C# To Java Overview.I have divided this guide into 3 sections. If you want to know the basics, read “Should Know”.  If you want to learn about some features that you may find useful, but probably aren’t necessary for you to start programming in C#, check out “Could Know”.  “Quick reference” is pretty self-explanatory, just Java keywords and their C# equivalents!

Should Know

The first thing to know is that luckily for you, C# and Java are very similar!  Quite a bit of Java code could be copy pasted into a C# IDE and compiled without errors, apart from some minor syntax issues.  However, Java and C# have some differences that you must know before you start coding in C#.  Let’s look at a code comparison.



public class Tester 
    public static void main(string[] args)
        boolean isRunning = true;
        String str = "I'm a string!";
        MyClass abc = new MyClass();

        for(int i=0; i < 10000; i++)
          abc.Process(i + str);
public class Tester 
    public static void Main(string[] args)
        bool isRunning = true;
        string str = "I'm a string!";
        MyClass abc = new MyClass();

        for(int i=0; i < 10000; i++)
          abc.Process(i + str);

Pretty similar, right?  Here are a couple basic syntax differences you should know off the bat.  Check out the quick reference section for more syntax differences.

A Java "boolean" is a C# "bool".
A Java variable defined as final is like a C# const.
The "Main" method in C# is capitalized but in Java, "main" is not.
To import a class in Java you use "import", but in C# the term is "using".
For Java, inheriting a class uses "extends" and inheriting and interface uses "implements", but in C# both are indicated by a ":".

Your IDE will often auto-correct small syntax differences, but looking at other people's code will often reveal varying syntax.  Learn it as you go.


As I said before, C# and Java use slightly different syntax for inheritance.

public class B extends A implements Comparable 
{ ... }
public class B : A, IComparable 
{ ... }

Calling Base Constructors

To call a superclass’s constructor in Java, you use super().
In C#, use base() in a similar way.

public Game(int level)


public Game(int level)
: base(level)


Calling Overriden Methods

Java and C# both require knowledge that a base class’s method
should override a superclass’s method.  To call the original
method within that, use base.

public void Update()


public override void Update()

Foreach loops

The syntax for foreach loops is a little different between the languages.

for(int n : elements)
{ ... }


foreach (int n in elements)
{ ... }

Default Accessibility

In Java, when you don’t specify a class’s scope, it is protected by default.  In C# it will be internal, which means it can only be accessed from the same package.

class A //this class is protected
protected int _i;


class A //this class is internal
protected int _i;



This concept is different from anything in the Java language.  Structs look like classes and are initialized with the new operator just like classes, but they are treated like value types (ex. int).  Treat them like lightweight classes that are always passed by value (copied when passed as a parameter).  They also cannot inherit other classes or structs.

public struct Point
public int x;
public int y;

public Point(int pX, int pY)
x = pX;
y = pY;


In C#, classes and structs can have properties which act like getter and setter methods in Java.  They are called externally like public instance variables but are different because they hide the implementation details of the class.  They are context sensitive so a single property can act as both a get and a set!

public string Name
if (_myName == null)
return “Unnamed”;
return _myName;
_myName = value;  //value is whatever you pass into the property at a set

If this property was inside MyClass, you could call it like this.  Note how a property acts as a getter or a setter depending on the context.

MyClass c = new MyClass();
c.Name = “Alex”;  //calls the setter
string str = c.Name; //calls the getter

Could Know

These techniques are very likely to increase your programming efficiency if you have been trying out C#, understand the very basics, and want to know more about what C# can do for you.

Passing By Reference

Unlike Java, C# allows us to pass variables by reference instead of only by value (although by default it behaves the same as Java).out – use to get an uninitialized variable and give it a value.

publlic void Assign(out string s)
s= new string(“Hi”);

ref – use it to change an already initialized variable
Using this we can do a very simple thing that Java has difficulty with, modifying two objects within a single function.

public void Swap(ref string s, ref string r)
string temp = s;
s = r;
r = temp;

Nullable Types

Primitives usually can’t be set to null, for example a boolean is always either true or false.  But with nullable types, you can make a nullable boolean which can have a value of true,false, or null.  Just add a “?” to the type.  The same goes for ints.
int? x = 5;

Console.WriteLine(“The value of x is ” + x.Value);
x = null;

//prints 0

Operator Overloading

Like C++, we can overload operators for our own objects.
public static MyInteger operator -(MyInteger n)
return new MyInteger (-n.value);

Defining Identifiers In Pre-Processing

C# gives us the ability to create variables that are evaluated before compiling the file.  This is very useful if we want to for example define sections that should only occur in debugging.
We put these directives at the top of the file.
#define DEBUG

elements(i) = CalculateElement(i);#if DEBUG
log.Info(“Our current element is currently: ” + elements(i).ToString());
…Since DEBUG is a pre-processing directive, our if statement will be evaluated before we compile our project.  That means if we are building for a non-debug environment, anything within the DEBUG directive would be ignored at compilation.

In XNA, there are other pre-defined directives like #if WINDOWS and #if XBOX so we can write a single source file for multiple target platforms.  You can also define how some functions handle math.


Sometimes, we want a property or method to behave like an Enumerator, but we don’t want to write a lot of code when the actual logic is quite simple.  Using the yield keyword, we can make simple logic for an IEnumerable/IEnumerator.
public static string[] fruit = {“banana”, “apple”, “orange”, “pear”, “grape”};
public static string[] vegetables = {“lettuce”, “cucumber”, “peas”, “carrots”};
public static IEnumerable FruitAndVeg{
foreach(string f in fruit){ yield return f; }
foreach(string v in vegetables){ yield return v; }
yield break; //optional

public static void Main()
foreach (string produce in Test.FruitAndVeg)

Partial Classes

Classes can be implemented in multiple files with the partial keyword.


partial class Test{

Defining Aliases

Similar to typedef in C++, we can reduce our keystrokes by creating aliases with the using keyword.
using C = System.Console;…

Just be sure to not abuse it; if you alias too many things, your code will become very difficult for another programmer to read!

Quick Reference

C# keyword Java keyword C# keyword Java keyword C# keyword Java keyword C#keyword Javakeyword
abstract abstract extern native operator N/A throw throw
as N/A false false out N/A true true
base super finally finally override N/A try try
bool boolean fixed N/A params typeof N/A
break break float float partial N/A uint N/A
byte N/A for for private private ulong N/A
case case foreach for protected N/A unchecked N/A
catch catch get N/A public public unsafe N/A
char char goto goto readonly N/A ushort N/A
checked N/A if if ref N/A using import
class class implicit N/A return return value N/A
const const in N/A sbyte byte virtual N/A
continue continue int int sealed final void void
decimal N/A interface interface set N/A volatile volatile
default default internal protected short short where extends
delegate N/A is instanceof sizeof N/A while while
do do lock synchronized stackalloc N/A yield N/A
double double long long static static


else else namespace package string N/A


enum N/A new new struct N/A N/A strictfp
event N/A null null switch switch N/A throws
explicit N/A object N/A this this N/A transient




  1. Pingback: essayforme

  2. Pingback: Buy generic cialis

  3. Pingback: Viagra generika

  4. Pingback: Cialis generico online

  5. Pingback: Low cost viagra 20mg

  6. Pingback: Cialis online

  7. Pingback: Cialis for sale

  8. Pingback: Viagra canada

  9. Pingback: Cialis uk

  10. Pingback: Cialis 5 mg

  11. Pingback: Bangalore Escorts

  12. Pingback: Kolkata Escorts

  13. Pingback: Goa Escorts

  14. Pingback: Ambika Ahuja Jaipur Escorts




  18. Pingback: XXX PORN Dhruvi Jaipur Escorts


  20. Pingback: Jiya Malik High Profile Jaipur Escorts Model




  24. Pingback: Selly Arora Independent Bangalore Escorts

  25. Pingback: Enjoy With Jaipur Escorts Tanisha Walia


  27. Pingback: Bristy Roy Independent Bangalore Escorts


  29. Pingback: Bangalore Escorts Sneha Despandey


  31. Pingback: XXX PORN Radhika Apte Model Escort

  32. Pingback: Buy cialis

  33. Pingback: Buy cialis online

  34. Pingback: Buy cialis online

  35. Pingback: Cialis coupon

  36. Pingback:

  37. Pingback:

  38. Pingback: go to the page cvmUHJ

  39. Pingback: click for details KqG

  40. Pingback: link to the page

  41. Pingback: click to to learn more

  42. Pingback: click to to learn more

  43. Pingback:

  44. Pingback: visit web page

  45. Pingback: find out more TLs9s

  46. Pingback:

  47. Pingback: please click for source

  48. Pingback: click to find out more seXMww

  49. Pingback:

  50. Pingback: page

  51. Pingback: page icI

  52. Pingback: more info zfZRZ

  53. Pingback: more detailed on this page

  54. Pingback:

  55. Pingback: visit web page

  56. Pingback: on this page

  57. Pingback: more detailed on this page zuka

  58. Pingback: as reported here

  59. Pingback: see more

  60. Pingback: visit web page

  61. Pingback: click at this page

  62. Pingback: click to go

  63. Pingback: continue 5zE

  64. Pingback: continue reading VIxz

  65. Pingback: visit web page

  66. Pingback:

  67. Pingback: here is the link

  68. Pingback: here is the link

  69. Pingback: Ruby Sen Kolkata Independent Escorts

  70. Pingback: Diana Diaz Goa Independent Escorts Services

  71. Pingback: Diksha Arya Independent Escorts Services in Kolkata

  72. Pingback: Devika Kakkar Goa Escorts Services

  73. Pingback: Rebecca Desuza Goa Independent Escorts Services

  74. Pingback: Yamini Mittal Independent Escorts Services in Goa

  75. Pingback: Simmi Mittal Kolkata Escorts Services

  76. Pingback: Kolkata Escorts Services Ragini Mehta

  77. Pingback: Navya Sharma Independent Kolkata Escorts Services

  78. Pingback: Elisha Roy Goa Independent Escorts Services

  79. Pingback: Alisha Oberoi Kolkata Escorts Services

  80. Pingback: Divya Arora Goa Independent Escorts Services

  81. Pingback: Simran Batra Independent Escorts in Kolkata

  82. Pingback: Ashna Ahuja Escorts Services in Kolkata

  83. Pingback: Sofia Desai Escorts Services in Goa

  84. Pingback: Goa Escorts Services Drishti Goyal

  85. Pingback: Mayra Khan Escorts Services in Kolkata

  86. Pingback: Sruthi Pathak Escorts in Bangalore

  87. Pingback: Ambika Ahuja Jaipur Escorts Services

  88. Pingback:

  89. Pingback: on this page

  90. Pingback: just click for source

  91. Pingback: sirius movs8518

  92. Pingback: linkshit videos2642

  93. Pingback: click to find out more

  94. Pingback: sirius latest movs649

  95. Pingback: alexnaraghi.com124

  96. Pingback: alexnaraghi.com601

  97. Pingback: alexnaraghi.com997

  98. Pingback: alexnaraghi.com466

  99. Pingback: alexnaraghi.com642

  100. Pingback: alexnaraghi.com362

  101. Pingback: comment301

  102. Pingback: comment611

  103. Pingback: comment360

  104. Pingback: comment925

  105. Pingback: comment395

  106. Pingback: comment824

  107. Pingback: comment930

  108. Pingback: comment469

  109. Pingback: comment435

  110. Pingback: comment749

  111. Pingback: comment348

  112. Pingback: comment797

  113. Pingback: comment671

  114. Pingback: comment654

  115. Pingback: comment340

  116. Pingback: comment75

  117. Pingback: comment141

  118. Pingback: comment574

  119. Pingback: comment167

  120. Pingback: comment803

  121. Pingback: comment366

  122. Pingback: comment915

  123. Pingback: comment551

  124. Pingback: comment296

  125. Pingback: comment173

  126. Pingback: comment226

  127. Pingback: comment623

  128. Pingback: comment191

  129. Pingback: comment778

  130. Pingback: comment391

  131. Pingback: comment798

  132. Pingback: comment829

  133. Pingback: comment603

  134. Pingback: comment916

  135. Pingback: comment935

  136. Pingback: comment212

  137. Pingback: comment249

  138. Pingback: comment706

  139. Pingback: comment113

  140. Pingback: comment158

  141. Pingback: comment757

  142. Pingback: comment445

  143. Pingback: comment632

  144. Pingback: comment342

  145. Pingback: comment969

  146. Pingback: comment216

  147. Pingback: comment62

  148. Pingback: comment735

  149. Pingback: comment634

  150. Pingback: comment515

  151. Pingback: comment325

  152. Pingback: comment387

  153. Pingback: comment774

  154. Pingback: comment792

  155. Pingback: comment711

  156. Pingback: comment73

  157. Pingback: comment483

  158. Pingback: comment812

  159. Pingback: comment715

  160. Pingback: comment41

  161. Pingback: comment817

  162. Pingback: comment312

  163. Pingback: comment601

  164. Pingback: comment499

  165. Pingback: comment646

  166. Pingback: comment577

  167. Pingback: comment289

  168. Pingback: comment51

  169. Pingback: comment460

  170. Pingback: comment856

  171. Pingback: comment188

  172. Pingback: comment376

  173. Pingback: comment436

  174. Pingback: comment246

  175. Pingback: comment660

  176. Pingback: comment791

  177. Pingback: comment604

  178. Pingback: comment116

  179. Pingback: comment339

  180. Pingback: comment400

  181. Pingback: comment198

  182. Pingback: comment418

  183. Pingback: comment114

  184. Pingback: comment8

  185. Pingback: comment260

  186. Pingback: comment784

  187. Pingback: comment822

  188. Pingback: comment615

  189. Pingback: comment316

  190. Pingback: comment36

  191. Pingback:

  192. Pingback: comment168

  193. Pingback: comment674

  194. Pingback: comment988

  195. Pingback: comment404

  196. Pingback: comment966

  197. Pingback: comment614

  198. Pingback: comment434

  199. Pingback: comment485

  200. Pingback: comment594

  201. Pingback: comment581

  202. Pingback: comment185

  203. Pingback: comment495

  204. Pingback: comment271

  205. Pingback: comment692

  206. Pingback: view more

  207. Pingback:

  208. Pingback: Sruthi Pathak Bangalore Female Escorts

  209. Pingback: click to see more

  210. Pingback: newtube sirius587 abdu23na6451 abdu23na8

  211. Pingback: sirius latest movs546 abdu23na5590 abdu23na39

  212. Pingback:

  213. Pingback: download on mobile354 afeu23na9256 abdu23na24

  214. Pingback: newtube tube planet998 afeu23na624 abdu23na97

  215. Pingback: download490 afeu23na7594 abdu23na0

  216. Pingback: 308QTQv8MUV

  217. Pingback:

  218. Pingback:

  219. Pingback: Sruthi Pathak Bangalore Escorts Services

  220. Pingback: see more

  221. Pingback: article source

  222. Pingback: more info uHNbk

  223. Pingback: provided link Dh2e2J

  224. Pingback:

  225. Pingback: based on these data

  226. Pingback: more info CdhOdK

  227. Pingback: link to a continuation

  228. Pingback:

  229. Pingback: more detailed on this page

  230. Pingback: more on the page

  231. Pingback:

  232. Pingback: click here

  233. Pingback: click to see more

  234. Pingback: this web page

  235. Pingback: read article owWP4m

  236. Pingback: a source

  237. Pingback: click here

  238. Pingback:

  239. Pingback: go here nKKeS

  240. Pingback: provided link

  241. Pingback: click to to learn more

  242. Pingback: based on these data

  243. Pingback: tube

Leave a Reply