Welcome to the dep dive. We're jumping straight into C Sharp twelve and dot Net eight today.
Yeah, a real powerhouse duo.
Definitely for building modern apps that well run pretty much anywhere. Our mission here is to kind of extract the essentials you need to navigate this stuff exactly.
We're drawing from a pretty comprehensive resource on C Shark twelve and dot eight.
Consider this your shortcut right setting up your dev playground, getting the Sea Shark basics.
And exploring those core programming ideas all within this latest dot net evolution.
Okay, let's unpack it. First things first, getting set up, choosing your environment right.
The big two are Visual Studio twenty twenty two and Visual.
Studio Code Yeah vs. Twenty twenty two, hugely popular with pro dot net devs, especially if you're mainly on Windows.
It's that full ide experience right out of the.
Box exactly guides you through set up you know, Sea Shark settings, choosing your theme, which is surprisingly important.
Oh yeah, staring at it all day, you want it to look right. Uh.
True, It's packed with features, so if you're deep Windows want that all in one feel. Vs. Twenty twenty two is probably your best.
Bet, but then you've got Visual Studio Code the contrast. Yeah, it's big selling point is flexibility runs everywhere Windows, Mac, Linux, Yeah, even arm chips like Apple Silicon or Raspberry Pie.
Super lightweight design too, right, And for.
Dot network in vs code, the c Shark DevKit extension is well essential.
Ah yeah, tell us about that.
It brings in the features you need for like managing solutions with multiple projects. Really turns vs code into a proper dot net environment.
So if you valued that cross platform agility and maybe work across different ocs.
Or you just prefer a more modular, bill it yourself kind of.
Editor, vs code with the DevKit is a strong contender totally.
They even have that insider's version if you like living on the edge getting new features early.
Okay, So organizing projects this idea of a solution.
Yeah, that's key in both Visual Studio and vs code with the DevKit.
Think of it like a binder, right, holding all your related projects together.
Exactly your website code, maybe a class library, a console app. The solution file groups them. Let's the tools manage them as one unit.
Our source mentions a chapter one solution holding a Hello CS project.
Classic example, and that ties into the dot Net SDK, the Software.
Development kit, which gives you the command line interface the CLI.
Right fundamental for creating and managing projects. No matter which editor you use.
You can use the CLI to spin up a new console app, for instance, yep.
And it generates those basic files, the dot c Proja project file program.
Dot cs and those bin and obj folders you see pop up, and.
The c sharp DevKit in vs code just picks up those solution files and knows what to do.
So the CLI is kind of the bedrock. Interacting with the core.
Tools absolutely and understanding solutions is vital as your apps get bigger, more complex, maybe split into different parts.
Okay, let's actually build something super basic, a console app.
Walk is through it right.
You typically use a template, right, the c shark console app template yep.
Give it a project name.
Like hellocs, choose where to save it maybe CR twelve, dot.
Net eight, and name the solution like chapter one.
And there's that interesting option mentioned about disabling native aot publish.
Yah ahead of time compilation piles straight to machine code.
Faster startup, smaller size in some cases, but we'll park that for now. It's covered later right.
So once you create the project.
You get this program dot cs file and it's usually super simple at first.
Often just a comment and maybe one line of code like console right line.
It's deliberately minimal, a clean slate.
And a good place to start poking around, like finding out the name space of that default program class.
Oh right, the source had that snippet type of program dot namespace.
String nameycal type of program dot namespace none, console right line namespace dot e something like that.
Just a handy way to see how your code's.
Organized, definitely, and you can take that further, get environment info like the current director jarn director yeah, or the OS.
Version environment do OS version version string in that name space.
Again, just useful for seeing where your code is actually running. Good for debugging, like.
A quick health check of the environment.
Exactly what OSM I on? Where are my files? Useful stuff.
One last dev environment tip. They mentioned inline hints or inlay hints.
Oh, those are great little reminders right in the code.
Yeah, they show the parameter names when you're calling a method, so.
You don't have to keep jumping back to the definition exactly.
Saves a lot of cognitive load. You can turn them on in VS twenty twenty two's options.
Tools, Options text Editor, c shap advanced inline hints somewhere in there.
And in VS code you just search settings for inline hints.
Small feature, big impact on readability.
Sometimes totally agree. Okay, moving on C sharp fundamentals, grammar, vocabulary, the building blocks.
Right, So the C shark compiler is called Roslin.
Think of Roslyn as the translator takes your C sharp.
And turns it into intermediate language.
Which gets stored in assemblies of those DLL or ex files YEP package code.
Then the dot Net run times Virtual Machine core CLR that's the engine kinda it uses it just in time, or JIT compiler.
Which translates that IL into.
Native CPU instructions. The stuff your actual process or understands happens at runtime.
So C sharp to IL with Roslin, then IL to native code with the JIT and core CLR.
You got it. It's a neat separation. Let's see sharp evolve kind of independently from the runtime details helps with cross platform two makes sense.
Now, C sharp grammar, we're talking statements.
Blocks, code inside curly braces and comments crucial for explaining things. But the advice is, yeah, the implicitly or globally imported. Saves you typing using system or using system dot collections generic all the time.
Where does that info live?
It's generated in that of data bug Net eight point zero folder, usually in a dot global usings dot g dot c s file. We're similar.
So for basic console app Microsoft dot net SDK, you get systemsystem, dot io, system dot.
Link common stuff, and if it's a web project Microsoft dot net sdk web you get more like asthmiccore stuff net dot HGDP Jason.
It's just about reducing boilerplate, making common types easy to.
Access precisely, less clutter, focus on your.
Logic, and finally literals simple concepts.
Yeah, just the way you write fixed values directly in your code, like the number.
One, two, three, or the text hello or true.
False, exactly the raw value itself written in the source.
All right, let's talk about scoring different kinds of data, starting with texts.
Okay, so the basic unit is char for a single character.
But there's a catch with unicode.
Uh huh. Some characters, especially emojis, are less common. Symbols might actually need two char values called surrogate.
Pairs, so one visual character doesn't always equal one char variable.
Exactly something to be aware of if you're doing low level text manipulation. Got to handle Unicode properly.
Good point.
What about numbers, lots of options. For whole numbers, you've got integers, int is common handles positive and negative, int is unsigned only.
Positive, and for numbers with decimal points.
Floating point types float, you need an F suffix like three point one forty f and double, which is the default if you just right say three point one.
Four, and then there's decimal for high precision.
Right crucial for financial stuff yeh, where tiny rounding errors are bad news. Use an M suffix like twelve point nine to nine ter.
So the difference is memory, use range of values and that precision.
Aspect spot on integers for whole numbers, floats doubles for general fractional numbers, decimal for exact decimal.
Representation, and we can check their size yep.
Using the size operator tells you how many.
Bites they take up, and find their limit.
Mind value and max value properties on the types themselves, like into dot minvalue, double dot max value.
The source had that classic point one plus point two.
Example, right, yeah, showing how double might give you point three zero zero zero zero zero zero zero zero zero zero four. Well, decimal gives you exactly point three. It's because of how they store the numbers internally.
Fascinating. That precision difference is huge sometimes.
It really can be. Understanding the tradeoffs is important.
What about those huge integer types in one two eight.
H yeah, system dot in one two eight and U twenty two eight added in dot net seven massive sixteen byte integers.
But using size klanumum is.
Tricky, requires unsafe code and a compiler flag. Definitely an advanced feature for specialized needs like really big numbers and calculations.
Got it back to basics. String for text.
YEP sequences of characters pretty straightforward, has a length property.
And they're immutable. Right. You can't change a string once it's created.
Correct. Operations that look like they modify a string actually create a new string. Important for performance if you're doing tons of manipulation.
Okay, now var the keyword var?
Oh yeah, tech difference superhandy.
What's the compiler figure out the type exactly?
Instead of string message hi, you can just write var message hi and.
The editor usually shows you what type it an YEP.
Hover over var and it'll tell you a string.
Makes code shorter, but maybe less explicit.
Sometimes it's a balance. Great for complex tykes where spelling it out is noisy, but sometimes being explicit makes things clearer.
Use it wisely, right, Okay, back to console apps.
For a sec text based run from the command line.
Good for scripts, simple tools, learning.
And importantly they can take arguments from the command line.
We'll get to that first. Making the output look nice. String formatting several ways to do it.
The classic placeholders console right line.
Name, name, age aw that style yep.
Or you can use named arguments for clarity, especially with multiple parameters of the same type.
Like console dot right line arg one first R one second right.
The source also mentioned boxing warnings.
Yeah said it's more unity thing less critical for general dot net apps covered here.
Okay, big one though.
Yeah.
Culture's impact on formatting.
Oh yeah, numbers, dates, currency, They look different depending on region settings.
Five versus doc A, comma versus dot for one thousand separators.
But you can control it.
Yeah, definitely specify a culture like culture info invariant culture for consistent machine readable formats, or.
Use custom format strings like zero for zero, placeholder hashtag for digit exactly.
Table two point eight in the source has details lots of control.
There, and the easiest way often is string interpolation. The dollar sign syntax.
Variable yep usually much cleaner. Console right line.
H reads nicely okay, nullable reference types nrts. Big change in modern C sharp.
Huge designed to tackle those dreaded noull reference exception errors.
By adding a question mark spring right.
It tells a compiler this variable might be null, and.
The compiler then warns you if you try to use it without checking exactly.
It performs static analysis to find potential null issues before you run. The code makes things much safer.
But you still have to handle the null case right. The knot is a warning system precisely.
It forces you to think about nulls, but you still need if my string null checks or similar patterns. It doesn't magically fixed nulls. It makes them explicit. Got it?
Okay? Command line arguments? How do we get those?
When you run your app like dot Net, run first arg, second.
Arc Those first arg second arg pieces.
They get passed into your main method as an array of strings, usually called arcs string arcs.
So urg zero would be first RG, ARGs one would be second arc yep.
You can move through the arg's array and use those values to change how your app behaves. Super useful for making tools flexible makes.
Sense, and that platform specific example, setting cursor size.
Right works on Windows throws an exception on MCLINICX A.
Good reminder that even with cross platform dot net, the underlying OS still matters.
Sometimes absolutely, and the solution often a tricatch block.
Try to set the cursor size, catch the exception if it fails on Linux or Mac exactly.
Graceful handling of platform difference. We'll dig more into trycatch soon.
Perfect segue. Let's move into core programming concepts, starting with operators.
Basic math, your bread butter plus AA for AD, subtract multiplied divide and per modulo the remainder after division ten percent three is one?
Got it? Logical operators and for a ing for R and they have that short circuiting behavior.
Yeah, that's important. With Andy in if the left side is false, it doesn't even look at the right.
Side because the whole thing must be false anyway, right And.
With Andy and if the left side is true, it skips the right side because the whole thing must be true.
Good for performance avoids unnecessary.
Work usually, but be careful if the right side expression has side effects you rely on happening.
Like calling a function that's supposed to always log something it might get skipped exactly.
Can lead to subtle bugs, something to be aware of, okay.
Making decisions.
Switch statements a way to handle multiple choices based on a single value, cleaner than lots of if l's ifs.
Sometimes you have case labels for specific values, a default case for everything else, and C shark allows go to within a switch jump to other cases.
It does. Yeah, use with caution, though can make code harder to follow if overused.
Right and then There are switch expressions in newer C sharp versions.
Yeah, C sharp eight onwards. More concise, often more powerful, especially with pattern matching.
That example with animals was cool checking the type and properties.
Cat four legged cat when four leggd cat legs equals.
Four that kind of thing, or just matching the type cat cat or property pattern spider spider when Spider's poisonous.
Handling null using the discard as a default, very expressive, often leads to cleaner code for complex conditions.
Definitely looks more functional, more declarative.
It leans that way, Yeah, okay. Storing collections a raise the basic fix size collection string names, new string three.
Create space for three strings, access them with indices starting at zero always.
Zero based name zero, names one, names two.
And loop through them with a four loop and the link property.
I names length iplus plus new names standard stuff.
What about those inline arrays and c share twelve ah more of.
An advanced behind the scenes performance thing for the runtime team.
Mostly so not something you typically declare yourself in application code.
Probably not directly no, but you might benefit from libraries using them under the hood. There's a link if you want the deep dive on those.
Gotcha and formatting output again.
Aligning column yeah, index alignment yeah, like zero zero twelve pads with spaces to align right in a twelve.
Character call, and showing binary index ed format string.
Like zero three four point b three two shows a number is thirty two bits. Binary representation potentially padded useful for low level inspection.
Okay, getting data in parsing strings to numbers.
Or dates, big parse, daytime dot parse common methods, but they.
Can fail throw exceptions at the string. Isn't it right?
Yep, format exception. That's why culture matters too, cultureinfo dot invariant culture to avoid nasty surprises with different date or number formats.
So the safer way is tripars.
Generally yes. In trpars input string out in a result, it returns true or.
False, true if it worked, and the result variable gets.
The value false if it failed, and result gets a default value like zero for end no exception thrown.
Much cleaner for handling potentially bad user input avoids the overhead of exceptions for expected failures.
Exactly use pars when you're sure the input is valid. Trypars when it might not be.
And if parse does thrown exception or something else goes wrong. That's where tricatch finally comes in.
Right wrap the risky code in try.
Handle specific errors in catch format exception x or.
More general errors in catch. Oh, I say, and use finally for cleanup. Code that always.
Runs, always runs, whether an exception happen or not, whether it's caught or not. Good for releasing resources like closing files. Essential for robust code.
Okay, integer overflow numbers getting too.
Big Yeah by default se sharp injurer math is unchecked. If indemac's value plus one happens, it wraps around silently to int men value.
Which can cause very weird bugs.
Totally, so you can use the checked keyword.
Either as a block yeah result large number one plus large numb.
Two, or as compiler option for the whole project.
And if overflow happens inside a checked context.
It throws an overflow exception instead of wrapping silently makes the error obvious.
There's a slight performance cost, but often worth it for correctness.
Definitely something to consider, especially with financial or critical calculations. All right, getting near the end functions or methods in C sharp reusable blocks of code key for organization. The example was time stable took a required number.
And an optional sized parameter with a default value void. Time stable INNT number in size.
Is twelve, meaning you can call it with just the number time stable five and size default.
To twelve, or provide both time stable five twenty.
And using named arguments makes calls clearer. Time stable number five size twenty.
Especially useful when there are multiple optional parameters or parameters of the same type. Improves readability quick terminology.
Check parameter versus argument.
Parameter is the variable in the function definition in number in size. Argument is the actual value passed in when you call the function five twenty.
Got it and functions can return values too.
Of course, the calculator tax example took an amount and reagencode.
Used to switch expression based on the region.
And return the calculated decimal tax value return calculated tax.
Perfect for encapsulating a calculation.
Or rule absolutely and documenting these functions.
XML comments Yeah, those triple slash comments summary summary editors.
Pick those up and show them as tooltips when you're calling the function.
Explains what it does, parameters, return value. Huge help for maintainability, good practice definitely.
Lastly, that decline larrative versus imperative style comparison.
Using the Fibonacci sequence.
Fib functional usercursion and a switch expression describing what fibonacci is.
While fib imperative used a loop describing how to calculate it step by step.
Just shows there are different ways to think about and solve problems in code. Neither is always better, depends on the context.
A good illustration of different paradigms yep.
Functional style often emphasizes immutability in expressions. Imperative focuses on mutable state and step by step instructions. Wow.
Okay, that was quite the journey through the fundamentals.
We covered a lot. Setting up the environment vs versus vs code.
See shirt grammar, Roslin, il jit, data types like char, int, decimal, string, Nobel.
Types, operators, switch statements and expressions, arrays, parsing, exception handling with trycatch.
Checked overflow, basic functions, parameters versus arguments, returning values, XML comments, and even a peak at programming styles.
Phew. Yeah, these really are the core building blocks you need for getting started with c SHAR twelve and dot net eight.
Having a solid grasp of this stuff is just crucial for building anything substantial and reliable.
Couldn't agree more. It's the foundation for everything else.
So as you the listener, continue exploring this, maybe something specific caught your ear.
Perhaps nullable reference types, or you want to know more about collection types beyond arrays like lists or dictionaries, or maybe.
The details of the Roslin compiler or the subtleties of decimal versus double.
Yeah, the point is mastering these fundamentals really opens the door to the more advanced, powerful features of dot net, so.
We definitely encourage you dive deeper. Check out the links, explore the official documentation. This platform is incredibly rich and constantly evolving. There's always more to learn.
