Learning .NET, C#

is it worth it?

--

Since my university days, I’ve been learning and using many different programming languages. Starting with C (of course) and then moving on to C++ (Object-oriented programming). When I started working initially I coded in Java, a bit of Python, then some Ruby and mostly JavaScript / TypeScript frameworks for the last few years. #NestJS #ReactJS

C → C++ → Java → Python → Ruby → JavaScript → TypeScript

Every language has their pros and cons. It is great if you are proficient in one of them, but it is also helpful if you are “good enough” to find your way around in any of them. However…

Now I need to use C# (.NET) due to reasons… so

What is .NET (dotnet)?

It is a free, open-source, cross-platform development platform. You can create any app on any platform. Although F# and Visual Basic are possible programming languages, C# is the most commonly used.

  • .NET was started by Microsoft in late 1990s and .NET Framework was released in 2002 with the goal to simplify Windows app development.
  • Then in 2016, .NET Core was introduced as open-source, cross-platform framework.
  • Later in 2020, they were unified and .NET 5 was born.
About .NET NGWS → .NET Framework → .NET Core → .NET 5/6/7/8

Of course, it might be better to use Visual Studio but also VS Code can work seamlessly. You might probably feel comfy with VS Code.

Why .NET?

1️⃣ You can basically create anything on any platform you want.
- Web ✅ Mobile ✅ Desktop ✅ ML ✅ Game ✅ …

2️⃣ .NET applications provide faster response times and require less computing power. Faster than Node.js, Java… 😲

performanceWeb Framework Benchmarks Round22

3️⃣ Large ecosystem of 5 million developers (+1 😂) , 100k contributions, 3'700 companies and 400k unique packages to help you create.

NuGet — package manager

4️⃣ It is considered secure, “loved” by developers (Stack Overflow survey) and apparently helps your productivity with VS family, developer program and advanced features. #IntelliSense #LINQ #AsyncProgramming

2021

Getting started

Let’s start with downloading .NET software development kit (SDK) and installing it. We would need it to create, build and run our stuff.

SDK includes everything you need to build and run .NET applications

Download .NET SDK → install → check in CMD

Then we will setup VS code (in case you don’t have it already) and also install “C# Dev Kit” for our convenience.

Compared to Visual Studio it is much lighter, and there are tons of extensions.

Download VS Code → Install → Install extension

Now we can just dive into coding by creating a new project (Console app). Then run it (F5) so we can see the infamous “Hello World” 🌍

Ok. Now we are in the business 😁. Let’s try to make a new Web API project and go through what we have in the code.
- New project → ASP.NET Core Web API → <name>

Project files

We can see that many files are created. In launchSettings.json → profiles-http is configured to run on “http:localhost:5270” with Swagger. In Program.cs → GET “/weatherforecast” API is defined.

Swagger helps users build, document, test and consume RESTful web services.

launchSettings.json → Program.cs

When we run it (F5) we can test it via Swagger UI or .http file.
- or use “dotnet run” in the integrated terminal

Now lets try adding a package Entity Framework Core for database.

dotnet add package Microsoft.EntityFrameworkCore.InMemory — version 8.0
add package EF Core → add model & db context → use in Program.cs

So far so good? We can continue with Docker, Docker Compose, and also GitHub co-pilot in the next article. I have to say “AI” will at least double your productivity. For today we’ve learned a bit about .NET history, its’ advantages, general project structure and got our hands dirty with a little hello world + web API. See you next time 😄

--

--

Билигүн.Б (Програмч аав)
2B +1% better 2day

I am who I am... || өөрийнхөөрөө байхаас ичихгүй