I have been a java developer who has now started learning C#. Below are some of my learning in C# :
C# is not platform independent like Java and can only work on Windows.
In C# instead of creating Jar like java we create a dll.
In C# we use the inbuilt IIS server of OS instead of tomcat/JBoss etc.
C# has method names in Pascal case unlike camel case in Java.
What else apart from these should a Java developer learning C# keep in mind?
C# is platform independent. Microsoft makes .NET Framework on windows, Mono is the .NET Framework on Mac, Linux, and mobile. If you use .NET Core(This is preferred moving forward), it is cross platform. They removed concepts that were Windows centric and moved them into their own packages. .NET Framework is a shared component installed at the machine level. .NET Core does not use shared libraries. So you are deploying exactly the runtime you compiled it on. .NET Core is driven entirely by the package management system to bring in runtime components.
In Java, each class is compiled to a separate file, which are then gathered into a JAR. In .NET a Project is compiled into a DLL. You can then bundle 1 or more dlls into a NuGet package(NuGet is the packaged manager for .NET) which will also manage dependencies. So a Maven package is analogous to a NuGet package. A Project compiling to a DLL is equivalent to a Jar for a single library. But a jar is a more flexible unit of deploy since you can include any arbitrary java code in it.
In the Windows space, IIS is the web server. IIS, supporting .NET framework, is setup as AppPool(the executable) and AppDomain(the isolation container).
If you are running .NET Core, on any platform, it is just a binary module. You can plug it into IIS or Apache like you would any other mobile.
Something else to keep in mind, on C# they have Properties as the method of implementing getters and setters.
If you have a simple getter/setter, it will also support access restrictions.
This automatically creates private backing variable. The "Property" construct is an outgrowth of a legacy of COM. It would understand that a function called "get_Name()" and "set_Name" were related. So properties are just functions under the hood, and you can create custom backing code if you want.
Many things in C# are done with Delegates where Java would use objects. Delegates are a top-level language feature. Events, Lambdas, LINQ are just forms of delegates. You start threads and use Tasks(Promises) using delegates. Think of a delegate as a type-safe function pointer. If you want to do composition it is generally preferred to use generics and delegates instead of a bunch of objects.
How did Java programmers not commit suicide using Date() from Java 1-7?
Bill's very good explanation apart, let me suggest something I learnt at my expense: C#'s syntax is really similar to Java's, but under the hood they are really two different beasts, and such similarity could be deceiving.
Years ago I approached C# for the first time wrongly believing that, more or less, understanding deeply C# would be easy, given the pretty similar language syntax. I was wrong. Syntax is similar, underlying semantic is really different.
posted 3 months ago
Thanks. This information is useful to someone who is beginning to learn C# after doing Java for many years.
If you're gonna buy things, buy this thing and I get a fat kickback:
Create Edit Print & Convert PDF Using Free API with Java