This week we're going to learn a bit more about c#, which is a language that lives in the .NET environment. When learning any new languages, it's important to do a lay of the land, survey the tools, and try to get some solid ground under your feet by trying to find familiar concepts in this strange new world. Please understand: it is normal for this to feel foreign, strange, and like your legs are stuck in the mud! Learning a new technology is never easy. The key is patience, taking good notes, and saving helpful references like tutorials and sample projects so you can continue learning from working examples.
C# is a great candidate to help us learn a new server-side language for a few reasons. First, the latest version of .NET, called .NET Core, is open-source, cross platform, and modern. This lets us write code that uses drastically different features from what we're used to: statically typed, compiled, and object-oriented (class based). We'll also get our first look at code-first database design, database migrations, high-level database functionality, and an "enterprise framework" approach to software development.
Throughout this exploration, you will be using Google to find answers to common questions, follow along with tutorials, read documentation, search error messages, and generally spend more time reading than writing.
When learning any new technology, there's a few questions to ask in the beginning. I encourage you to do some googling to get some context around the c# language or any other language that you're interested in learning. Some of these questions may not be answerable until you've started playing with the language a bit.
Spend some time (~30mins) googling some of these questions to see what you can uncover.
- Is this language compiled or interpreted?
- Does this language use dynamic or static typing?
- What editor do you use to write code in this language?
- What plugins for the editor are popular?
- Is this a stable language or something more experimental?
- When was the latest release of the language?
- Who created this language?
- What is the most popular framework that this language uses?
- What is this language used for?
- What platforms is this language meant to run on?
Specifically about the language itself:
- How do you get to 'Hello World'?
- How do you print to the console?
- How do you run a program?
- What kind of datatypes are there?
- How do you make a number, integer, decimal?
- How do you make a string?
- How do you make a collection / list / array?
- How do you write a function?
Once you have started working out these basic questions about the language itself, you can start to ask questions about the general ecosystem:
- What package manager is used to install libraries?
- How do you write an HTTP API? Is there an http micro-framework or something built in?
- How do you connect to a database?
- How do you turn objects into JSON?
- etc.
Once you have done some googling, its time to get to work. C# is unique in that there are some really great resources available from Microsoft, including an online tutorial. My recommendation is to do the following:
- Work through the online tutorial. You don't need to install anything! It's just a friendly introduction to C#.
- Work through the C# in 10 minutes tutorial. This tutorial will also have you install the dotnet SDK, which is how you will write C# on your computer. NOTE: Install .NET 8 SDK (NOT just the Runtime) VS Code works great with C#, just be sure to also install the C# extension. Note: you will be using VS Code, not Visual Studio. Microsoft has done a good job at writing tutorials for both environments, but you should ignore any tutorial that specifically use Visual Studio.
- Continue learning about the language through the online documentation. The online portal is extensive and includes several tutorials including
Numbers in C#,Branches and Loops,List Collection, andIntroduction to C#(which includes some further exercises about classes). - Read up on Object Oriented Fundamentals in C# (at least the first 3/4)
- Read up on how to build Web APIs with .NET Core. The tutorial walks through building a "ToDo" app :). Many things may not make sense, that's OK. Get get a survey of the ideas.
- Google around for more introductions: "c# for beginners", "dotnet c# for javascript developers", etc.
The Microsoft online documentation has extensive introductory resources to c# and dotnet core in general. You can click through all of the resources on the left navigation pane to learn more. For example, the Tour of C# article is a helpful read that covers program structure, types and variables, expressions, statements, etc. The introduction to classes is useful but it's OK if you don't quite get to it.
Before continuing, please make sure that you have completed the following:
- You have installed the dotnet SDK and can run
dotnet --versionfrom the command line successfully - You can use VS Code to build a dotnet application (using
dotnet runordotnet watch run) and are using the c# extension - You have built and executed your first 'hello world' c# console application successfully.
- You have finished at least a couple of the introductory c# tutorials
The following questions are meant to help you build a foundation of vocabulary, to be completed after you've finished the introductory tutorials. Every new environment comes with new paradigms, keywords, and ideas. Some of these things are directly applicable to things you've already learned in other environments, others may be new. Some may be simply technical (like syntax), others may be completely new to you (like inventions specific to the .NET environment).
Work through these trivia problems as a group. Discuss and see what you can uncover!
- What similarities stick out to you between C# and JavaScript? What major differences?
- What does
varin c# do compared to JavaScript? - What is the difference between .NET Core and .NET Framework?
- What languages can you use in .NET Core?
- What does it mean to say that c# is a statically typed language?
- How do you create a new dotnet project from the command line?
- What is NuGet? How do you use it within dotnet?
- How do you represent a string in c#? What about numbers / integers / decimals?
- How do you create a List of integers? What about a list of strings?
- How do you loop over a list? How do you do an old-school for loop?
- What is
usingused for? - How do you write a function that takes in a string as an argument and console logs the string?
- How do you write a function that takes no arguments but returns an instance of a class
Human? - What is does a
public voidfunction do? - What is a class?
- What is a class property vs class method?
- What is the difference between an abstract and virtual class method?
- What does it mean for a class property to be
privatevspublic? What aboutprotected? - What are getters and setters?
More advanced topics, specific for web app development:
- What is 'Code First' database design?
- What are database migrations?
- What does MVC standfor? How is each part used in a modern web app with react?
- What is a dbContext as it relates to .NET?