C# in 24 hours

2016 Dec 6 at 00:33 » Tagged as :csharp, october curse, vs code, dotnet,

What the hell am I, an avowed microsoft hater doing with c#? What the hell is microsoft doing on github? When Visual Studio Code was announced for linux, I was more than sceptical. I scoffed at folks who tried it out. But now here I am having a crack at it myself. Right now I am on holiday at my sister's place in the hills. This is where I learned python a few years back. Maybe it's time to investigate C# . Let's see if it can be learnt in 24 hours. I will probably make a fool of myself with the comments I am making on this blog post and maybe even the next few posts as well. But never mind. The time now BTW, is 6:41 is in the morning. It's cold but very bright and sunny.

Program stucture.

The first thing that csharp hits you in the face with is Namespace. I rekon this is more like java packages than C++ namespaces. Inside a name space you can have classes and interfaces and we all know what they are. Less obvious was Using, this sounds a bit like import package.* in java. Shudder. But perhaps it's more like the same keyword in C++. The program entry point is public static void Main(string[] args) now where have I seen that before?

Types

Why does csharp have so many different types? Who in his right mind will bother with ubyte, ushort or byte instead of using plain old int? What's the good of toasting a few brain cells to save a byte of storage? And here we have the enum  One of my pet hates. That hatred comes from the enum in SQL, but as a result I am generally averse to it's use in other languages too. Not many people use it in python but lots of java folks do. Ccsharp's version seems to be something along the same lines. The struct keyword is straight out of C, so why is it needed in an object oriented language?

Delegates are a bit tricky, it seems to be like a pointer to a function in C which again raises the question of why it's needed, perhaps a better way to think of it would be to compare it to python function which are objects and can be passed around as parameters to other functions or perhaps Java predicates.

While still on the subject of types, you can always trust microsoft to make things as complicated as possible. Proof:

Nullable value types also do not have to be declared before they can be used. For each non-nullable value type T there is a corresponding nullable value type T?, which can hold an additional value, null. For instance, int? is a type that can hold any 32-bit integer or the value null.

Expressions

Nothing much to write home about here. Pretty much the same as almost any other language. Except for maybe checked and unchecked. If the expression is wrapped in checked it will not raise an exception if there is an arithmatic overflow.

Classes and objects

Again a well traveled path but the internal access modifier was something that I didn't quite get the hang of and I had to brush up on virtual methods to get it through to my head. After so much of Java and Python almost didn't recognize the ':' notation to extend a class as coming from C++. properties smell like @properties in python. Events and event handlers are going to take a bit of getting used to, specially because they are tied to delegates (which I am not 100%) with yet and also because event handlers are added with += and removed with -= . I suppose it does make some sense when you think about it.

This is beginning to look easy. Should have tried this out long before this.