â newbie - are 4-5 year old year c# resources still relevant?
Newbie trying to learn c# here. How much has c# changed over the last 4-5 years? I'm planning on watching this video (https://www.youtube.com/watch?v=GhQdlIFylQ8) but it's 4 years old so I'm not sure if the material would still be relevant.
Also are there any good resources you guys would recommend for beginners trying to learn c# and .net? I'm trying to learn them as they seem popular
freeCodeCamp.org
YouTube
C# Tutorial - Full Course for Beginners
This course will give you a full introduction into all of the core concepts in C# (aka C Sharp). Follow along with the course and you'll be a C# programmer in no time!
âď¸ Contents âď¸
â¨ď¸ (0:00:00) Introduction
â¨ď¸ (0:01:18) Installation & Setup
â¨ď¸ (0:05:03) Drawing a Shape
â¨ď¸ (0:17:23) Variables
â¨ď¸ (0:30:06) Data Types
â¨ď¸ (0:37:17) Working With S...
13 Replies
I'm also a beginner I still watched it during my spare time and on the side I go to microsoft documentation which help me to understand some changes before sleep time I tried to read some articles or listen to podcast about it
nothing to loose it is for you own sake let's DO IT! đ
The official Microsoft Learn are kept up to date from what I've seen
If you go with the video you posted, some things you need to look up afterwards to avoid pulling your hair out are global usings, top level statements and nullable reference types
I glanced at the video and he's using the + operator for combining strings. Nowadays you'll most commonly see string interpolation instead.
At the start of the section on Switch, he shows dummy code at 2:18:15. A similar syntax is now available with switch expressions
And lastly he uses Convert and if you ask anyone in this server, Convert to parse strings is the devil.
$tryparse
The TryParse pattern is considered best practice of parsing data from a string:
- a TryParse method returns
true
or false
to inform you if it succeeded or not, so you can use it directly in a condition,
- since C# 7 you can declare a variable that will be used as an out
argument inline in an argument list,
- it forces you to check if the out
argument contains valid data afterwards,
Avoid: Convert.ToInt32 â it's a bad choice for parsing an int
. It exists only for backwards compatibility reasons and should be considered last resort. (Note: Convert does contain useful conversion methods: To/FromBase64String
, To/FromHexString
, ToString(X value, int toBase)
, ToX(string? value, int fromBase)
)
Avoid: int.Parse â you have to use a try
/catch
statement to handle invalid input, which is a less clean solution.
Use int.TryParse https://docs.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-5.0#System_Int32_TryParse_System_String_System_Int32__ Int32.TryParse Method (System)
Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the operation succeeded.
The basics like loops, ifs, types, etc will still be relevant. But some best practices and libraries have changed
And of course a lot of new stuff has been added
Thanks guys for the resources! I'll probably binge watch the vid and look at the docs b4 looking into watching some vids on building a simple API
a core ideology of C# is that it only contains non-breaking changes as it goes forwards
everything from 5 years ago is still relevant, with new features just providing cleaner or simpler ways to achieve the same thing
C# 5 years ago is not going to be any different to a beginner than what it is now, with the exception of minimal APIs
C# changes try to keep older features or older ways of work intact, so you can later just check out most notable changes in newer versions of C#.
Something that left me confused recently was the NRT feature (Nullable Reference Types). It gives you additional warnings in certain cases to prevent possible Null Reference Exceptions.
If you have this enabled in your project you might get warnings in cases where people in older tutorials don't get them.
I had this disabled, probably due to an outdated template or other weird reason.
"Starting in .NET 6, they're enabled by default for new projects." https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references
Thanks for the heads up.
I'll be sure to look out for it đ
C# 10 added file-scoped namespaces, I don't think it's enabled by default, you can try adding a semi-colon after a namespace and it should be applied automatically (at least in Visual Studio). As someone who hates deep indentation I love it, so you can check that out if you'll like it.
Something similar to this is also the "top-level statements" feature, this one I think is toggled on by default now. I would find it very helpful as a beginner as you don't have to worry about Namespace, Usings, Program class, Main, args, identation etc. before even writting the first "Hello world!"
oh that's pretty neat. thx!
Yeah, the main one are top level statements, global usings and nullable reference types since the default settings on default projects force you into using them so it can be pretty confusing at first.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.