Programming Diaries — Day 1 — Starting C#

배우는 자(Learner Of Life)
5 min readJun 9, 2022

Getting to know namespaces, classes, methods, functions, …

#C#, #class, #method, #function, #parameter, #argument, #CLR

Finally starting to learn C#

What I did today

I have been signing up for a C# course when it was on sale for a few months on Udemy, but have not been able to take the course yet. Finally, as I found a new job as a tech expert with a good company, I realized that I need to get on learning the language. So I began to view the video lectures and installed the Visual Studio Community version on my MacBook.

While installing it, I had some time as it was not done as quickly as I wished it to be. So I looked for an online C# compiler so that I can at least practice and follow the video instructions.

While imitating the works of the instructor, I have acquired some useful information about the fundamental types of inputs that make up the basics of the language: namespaces, classes, methods, functions, parameters, and arguments.

So what each of these is, and how is it laid out? Let’s find out!

Namespaces are the ones that include the classes that have multiple methods and functions that perform certain tasks. For instance, in the picture below, there is a namespace called “System”, which includes a “public” type of class called “HelloWorld”. Then the class includes a “public static” type of “void” method or function. The method or function finally includes an argument or a parameter called “string[]”, which the CLR is making use of when the program runs. The content of each class and function must be denoted by a set of curly brackets({}) so that the program can find it when running. The name of the function should also be capitalized if it wants to be found.

Namespaces include classes, which include functions, which include arguments

An application is made up of building blocks called “classes”. A class is a container of data and methods. Functions or methods have certain behaviors that do something for the user. For instance, a car can have attributes of “make”, “model”, or “color”. It can also have functions such as “start()”, “move()”, etc. with “()” to denote that they are functions that take certain inputs.

A class is made up of data(attributes) and methods(functions). Attributes represent the “state” of an application. Methods include code that has logic, which allows us to write code and to implement algorithms.

As the application grows and has more classes, they must be organized. A namespace is a method of organizing these classes. A namespace organizes related classes, in other words, those with functions that are considered to be within the same domain. For instance, a class that has features to add, delete, multiply, or divide numbers, can be organized with another class that has functions to perform taking square roots, inverses, or powers of numbers. In reality, the domains of namespaces are usually distinguished into “data”, “graphics” and “security” which are distinctive features from one another, but fundamentally make up an application holistically.

Then also, as the application gets more complicated, the number of namespaces grows. Naturally, the namespaces can get messier. Namespaces can then be organized by an assembly file. An assembly file is usually denoted with extensions of DLL(dynamically-linked library) or EXE(executable) before a dot. DLL file includes code that can be used across different programs, while the EXE file only represents a program that can be executed. It is a file under the disk, acting as a container of related namespaces. Now the applications are not solely composed of namespaces, but of multiple assembly files, each of which contains many namespaces.

Thus, when compiling an application, it builds one or more assembly files, depending on how the code is partitioned.

What is CLR?

Previously, C/C++ had been compiled to a “native code” for the machine on which it was running. The problem was that this native code only worked for the machine with the same architecture for which the code was compiled. Microsoft created the .NET framework and C#, referencing how Java is built. Java, unlike C/C++, does not compile the code into native code, but rather compiles the code into “ByteCode”, an intermediate language that is not just geared towards a specific type of machine. Likewise, C# is complied into “IL (Intermediate Language) code” that is independent of the computer with which the code was running.

However, as the “IL Code” is not in the final target format, it has to be translated into something that a machine can understand. Now, this is where CLR comes in to play the role. CLR (Common Language Runtime) is an application that sits in memory and takes the job of translating IL code into machine code.

The entire process of translating human-typed(C#) code to IL code and finally into a machine “native code”, is called “Just-in-Time(JIT) Compilation”. This is why we do not have to worry about compiling every piece of human-readable work into a specific type of machine-readable “native code” as .NET Framework and CLR take care of it. As long as a machine has CLR, it can run the application built by a human with C#.

What is .NET?

It is a framework for building applications on Windows using different languages including C#. It consists of CLR(Common Language Runtime) that translates IL Code into machine-readable native code, and Class Library that allows building applications.

What to expect more in the future?

The void function does not return any value, which is the characteristic of the function. I expect to learn more types of functions in the future as I dive deeper into the world of C#. However, for a while as the function, “Console” includes basic features of reading and writing data, I expect to encounter this fellow a lot more in my journey. This one has a namespace mother called “System”, which I would also expect to see as often as its most significant son. I’d better be friends with these before any other.

P.S(Please See (if you would like))

  • The reason why it is called a “console” application: is because when the program runs, the console window pops up.
  • The JIT compilation is the compilation of IL code to native machine code at runtime.
  • Assembly: a file in the form of an executable or a DLL that contains one or more namespaces and classes. It is considered as being a single unit of deployment for .NET applications.
  • An application is made up of building blocks called “classes”. But in a large-sized application, these classes can be contained by namespaces, which multiple assembly files can also contain.
  • Ctrl + F5 to run the application
  • Ctrl + x to delete a line of code
  • If “Resharper” is installed: Alt + Enter allows the deleting of all unused lines of code

--

--

배우는 자(Learner Of Life)

새로운 것을 배우길 좋아하는 사람, 세상의 많은 것들에 질문이 많은 사람