From JS to C#
These notes are from a perspective of a JavaScript developer. I am trying to understand the similarities and differences between JavaScript (JS) and C#.
A Dictionary is like storing key and values in an object literal example:
The difference is that in JavaScript the key is always a string and you can have different type of objects in the same dictionary.
Note: In C# the key types are mostly strings or ints. I wonder if there is any other type useful for a Dictionary. I could think of Enums.
JS Arrays are like C# Dictionaries with key-value type of int.
HashSet
This looks like a List but it is un-ordered and has better performance. It would be like a JS Array but instead of Int key types it uses unique enums.
Anonymous Types
Example of anonymous types from MSDN
Lists are a wrapper on Array to make it usable as the JS Array.
Classes
C# Static classes are like JS Object literals. They can’t be instantiated, but the methods are usable.
eg. of a C# class in JS
Sealed Classes
Sealed classes are not inherited by any class but can be instantiated.
- Sealed classes can help keep the code shallow and simple. That is good to avoid the gorrilla-banana problem.
ReSharper
gives the compiler special instructions for the compilation of the file in which appears. The instructinos must be supported by the compiler. In other words, you cannot use
#pragma
to create custom preprocessing instructions.
The Microsoft C# compiler supports:
#pragma warning
Dependencies
Files in a project have access to all the dependencies declared in .csproj
- the keyword
using
is like import, which will bring into csproj a determined dependency.
Operators
Entry point
is a static method that serves as an entry point for a C# app and normally lives in a file named Program.cs. Sort of what index.js would be in NodeJS.
Provides properties for getting the information about the application, such as the version number, description, loaded assemblies, and so on.
Similar to package.json but without scripts, dependencies, etc.