Love this, great job. I'm an experienced programmer in other languages (C, C++, Java, etc.) and this is just the right level for me - not too little, not too much, perfect pace. It's great to have a quick survey, and when I need more detail I'd rather drill down into a written manual anyway than watch a video. Thanks!
you missed tuples, anonymous types, lambdas, exception handling, goto, LINQ operators like select, where, join ..., nested templates, virtual, polymorphism, RTTI, dynamic, default values, params, out, in, ref, const, enum, Lazy, IDisposable, garbage collection, lock, parallel... the list is much longer. But still a good video to get an overview.
6:55 It´s important to mention that the using keyword in C# does NOT include the entire System.Collection.Generic but just makes it easier to type collection type in that file. Like instead of having to write System.Collection.Generic.Dictionary myDictionary = new System.Collection.Generic.Dictionary(); we can ommit System.Collection and just write Dictionary myDictionary = new Dictionary(); instead.
very nice, I have been using C# for 15 years, read books, watched other videos etc. yet this is really useful and educational in just a short video. Thank you !
I can only view this video as someone that knows C#, but I can say it was really good on catching me back up. It's been 3 months since I last coded and I feel I'm pretty back up to speed. Of course this is only general stuff. But it's a good start to learning/remembering.
Some error in the narration: of course you can have public methods on private classes. That makes perfect sense. You really have to correct this error as it is quite important.
> these days C# developers will almost exclusively use var That's a very dangerous thing to say seeing all the heated discussions that come up everywhere once you say you either want var only, concrete only, or even a mix You used both Destructor and Deconstructor terms for showing Deconstructors, only a small error but Destructors are vastly different from Deconstructors! Aside from that, cool video. I genuinely think this is a good overview!
I very much disagree with what you say about `var` and implicitly typed variables at around 0:55. You make the very bold claim that implicit typing is good without any support of that claim. Implicit typing is a tool, and just like all tools, there are good and bad ways to use it; situations that call for the tool and situation that said tool should be kept far away from. Implicit typing should be used when, and only when, the inferred type is obvious to the reader and should be. If the inferred type is in any way obscured or non-obvious to the reader (for example, when storing the return value from a method or property in another class), the variable type should be explicitly declared. Note I said the reader, not the compiler and not the author. Just because the type is obvious to the author at the time of writing does not mean it will be obvious anyone else or to the author at a later time. Ultimately it is all about legibility. Our code must be legible; illegible code is difficult to maintain and modify. Implicit typing is a tool to make writing code easier, but ease of reading always needs to take priority over ease of writing if the code is to have any longevity.
Most C# does still use var, and there are good things about it, like reduced refactoring at the caller if a type changes. The reason it's generally still readable is that the IDE is good at providing the type information. That said it's starting to move back away from var in some places, with nullable reference types and the new keyword e.g. T t = new();
@@diadetediotedio6918 You left out the "without any support of that claim"-portion in the original post. OP however did have a support for his claim of drawbacks of using var. Whether you agree it or not is different topic.
@@ManWithoutThePants No? He never put any support on his claim, that's why I made my comment. His claim was purely based on his personal opinion on the subject, which it is pretty easy to understand that the sir making the video also have.
var value = 55; var result = value switch { 1 => "one", 2 => "two", 3 => "three", _ when value > 10 => "greater than 10", _ => "unknown" }; Console.WriteLine(result);
C# is a bit confusing for me because I've worked with C++ but never worked with OOP much, other than simple game scripting in C++ This video just gives a very quick overview of some of the functions of C#, but not all... THanks, but it was tough to follow for me.
What if you have a mutable type in a record, like an array? I assume you can change that? Asking as a functional programmer. Interesting about the => notation. Is there no final / const keyword? Is that to take the place of final / const? That's rather unusual that instead of returning a tuple of values, the deconstructor actually includes the values in the parameters. How does that work if you don't care about one of the values? I find the PascalCase / CamelCase a bit off-putting, as I do the C-style convention of putting the opening brace on its own line... it just takes up so many more lines of code than putting it on the line where the class / method / etc. is declared. Can methods be declared with a var return type to have auto type deduction? How in-depth is the pattern-matching? Again, as a primarily functional programmer, some languages have really amazing pattern matching abilities. Don't worry about answering these... it's just me thinking out loud. This was an awesome video. I just got the Functional Programming in C# 2nd ed book from Manning to jump in feet first, but having never really used C# before (although knowing Java, Kotlin, and Scala well), this has been a really handy introduction to cover the basics that may well get me up to speed to the point where I can read the book without needing to go through a beginner text. And yes to Rider! I love me some JetBrains and buy the yearly subscription. CLion is the only C++ IDE that I can not only tolerate, but actually enjoy using.
When I saw the title I already knew that it would not fulfill it's promise :D. Almost at every point I had something to complain. Though sometimes I might be a bit picky. 00:36 "Each line is ended with a semicolon". Well especially for new users of the language this can be misleading. Not every line has a semicolon at the end but every statement. It's a bit difficult to explain this in easy terms, though it's certainly not every line. Common beginner mistakes is putting a semicolon at the end of an if statement which would end the statement right there. So the following body has no connection to the if statement this way. 00:46 Besides line comments, there are multi-line comments using /* This is a comment */ 01:26 Just like to point out that the primitive type list is a bit longer than what was shown here ^^ 01:39 Well, he said DATA-types so we might forgive missing enums, delegates, interfaces and closures. 02:01 This is a common misconception. Structs don't live on the stack unless their variable is declared on the stack. Structs are value type and as such are directly stored in the memory of the variable itself. So it depends on where the variable is stored. When the variable is a field of a class, that struct would live on the heap. 03:00 This is just false. A private class can of course have a public field or method. How would you interact with anything in that class? When a nested class is declared private, it can only be used inside that class and can never be exposed to the outside. So you can not declare a public or ptotected field of your private class type since from the outside or a derived class, that nested class would not be visible. However the fields and method inside the private class can have the full spectrum of modifiers 05:20 Those unfamiliar with C# probably should know about logical and, or, xor and not operators which are &&, ||, ^ and ! respectively. Personally I get some itching when tutorials show boolean variables inside an if statement compared to true. An if statement simply requires a boolean value. Those logical operators will return / produce a boolean expression. However a comparison with true is completely unnecessary. You could also do if (aBoolVar == true == true == true) which does the same as if (aBoolVar). The comparison of boolean operators don't need to be used inside an if statement. You can also use them to assign a boolean value. bool myVar = someString == "Hello" && age > 18; 05:57 This is called a "switch expression" which actually evaluates to a value. A switch statement is actually a control flow statement which does not evaluate to anything, like an if statement or for loop. 06:49 Even though I don't like them because they have a lot of overhead, it should be mentioned that you can have multidimensional arrays as well. They may look useful, but the performance isn't that great. For every access it has to do a bounds check on each dimension / index and calculates the flattened index every time. In most cases, especially in time critical situations (when you create games and not business apps) just using a normal 1d array and calculating the index yourself can be way faster as you usually would use nested for loops and you can pre calculate some of the offsets in the outer loops. Also when it's a 1d array it's much easier to iterate over all elements regardless their spatial relationship. 06:55 Small mistake here. The System.Collections namespace does only contain the untyped / object variants of those collections. All the types shown there are inside the System.Collections.Generic namespace. You almost never want to use the untyped variants. They are essentially an ancient leftover. Even when you want to store System.Objects / objects, most people would still use the generic List with the type object rather than the ArrayList. 06:58 It should be pointed out that "importing" a namespace does not load anything like in other languages where some kind of import would actually load or embed another file. Such a using directive will "just" shorten the type names. So this is a pure organisational feature. We use namespaces to avoid name collisions. Different namespaces can have the same class / type names, but you can not "import" both as when you get a name collision, the compiler would complain as it can't tell which type you wanted to use. It's possible to "import" or resolve individual types by: using MyType = Some.NameSpace.MyType; Here we can even rename / give the type a file wide alias name 07.23 This is only partly true as the foreach loop does first and foremost use pattern matching and only resort to the IEnumerable interface when no pattern could be found. The pattern the compiler looks for is simply if the instance passed into the foreach has a method GetEnumerator and if the returned type has a MoveNext method that has no arguments and returns a bool, and it should have a Current property that is readable. If those conditions are met, the compiler will just use those methods, even without the interface. Most of the built-in collection types use struct enumerables / enumerators to avoid creating garbage on the heap. 07:34 Again, the generic version of the IEnumerable is in the System.Collections.Generic namespace. The untyped / object version is in the System.Collections namespace. 08:44 Just to use the right terminology, the stuff after the "where" keyword is called constraints. Several constraints can be specified by separating them with a comma. Note that all constraints need to be satisfied. If a generic class or method has more than 1 generic argument and you want to put constraints on more than one, you need to use another "where" for each argument you want to constrain. Just as a warning: Generics can be quite useful, but are often misunderstood. Many want to use them like polymorphism, however generics are somewhat the opposite of that. While deriving from a base class keeps the data of the base class but allows to overwrite functionality, generics actually keep the functionality the same while being able to exchange the data the function works on. Bound generic classes are usually incompatible with each other. So a List and a List are two completely separate types. In rare cases there can be exceptions with the right conditions (covariance / contravariance) but that are really rare usecases. 08:55 Well a lot is missing for it to be a video about all language features ^^. I know it can't really be comprehensive, but things that weren't really mentioned are: delegates (essentially typed function pointers), anonymous methods / closures, (ability to automatically capture variables in a scope object) lambda expressions, enums, nameof, all operators (there are a lot) operator overloading in classes type conversion operators events, CIL and the ability to decompile to other .NET languages extention methods, linq (I mean the LINQ syntax which is simlar to SQL, not the classes from the System.Linq namespace), attributes (essentially static metadata that can be attached to almost everything) params (essentially allows variable arguments as the last parameter of a method) exceptions (try / catch / finally) object initializer nullable types partial type declarations ref / out (pass by reference) indexer (allows a class to be used like an array or dictionary) using statement (not to be confused with the using directive at the top. It's used to automatically dispose objects) goto (Yes, C# has goto. Now forget that I mentioned it ^^) reflection Those are just some things of the top of my head. I only focused on language feautes, not framework features or classes. Now I've spend already too much time on this post so lets wrap it up. There's still a lot missing. If you want to learn more about the syntax, look up "C Sharp syntax" on wikipedia.
enums in C# are just a group of constants, usually integers. Color.Red=1, Green=2, Blue=3 etc. They don't wrap values like enums in some other languages like Rust. You can do that, just not with enums.
Goddam, I thought C# was going to be this whole thing, like learning to speak Spanish. But a year later I realise the actual vocabulary and rules could fit on a single note page. Wrapping your head around them and practising is the hard part.
Great point about delegates and extension methods I definitely missed those. Reflection I'd say is more a feature of .NET and not specifically part of the C# language spec. There might be uses of C# that don't support reflection. Maybe I'll do another video on features of .NET which can include all sort of things in the System namespace!
The benefit of implicit typing is that it is easier to write, but you still get all the benefits of the static types. It's a matter of opinion though, do you prefer explicitly typed variables? Some people do
I wanted to get oop principles ubder my skin to be capable truelly code anything. So I try to find language to made me truelly use it ( my first language, python, not really useful for that in my opinion). I choose java and C#. Because of this video i am going to focus only on C#. Thanks you.😊
Maybe I’m the only one here but I hate implicit typing with a passion. Why would I ever want to put a barrier up for knowing what type I’m dealing with? It feels to me that except in a few situations where you could get different types being returned to you and this gives you an option for how to handle that, that I’m always better off making the effort to be explicit in my use of types as it’s far clearer to read?
The worst thing is that they ruined the var keyword with respect to nullable reference types. Instead of introducing a separate "var?" statement to be explicit about a variable being able to hold null, they caved in to some people who wanted var to just always be nullable. Now, technically every variable declared with "var" is nullable in a nullable reference type context and will display as such when you hover the mouse over it.
It's okay, you can hate it all you want, it does not makes what you say true. My point is that knowing the type should not be more important than adhering to the contracts you put in your code using the types, and I don't think this is much of a "barrier" as you can pretty much still see the types.
I think i have c# brainrot, i love c# i like it alot its the perfect mix between usefull and simple, the language syntax just makes sense yet you can still do performant things when usings spans and things alike
Usually constructors and *destructors* are introduced alongside each other and not constructors and deconstructors. For one, many have heard of constructors and destructors but few may have heard of deconstructors and, as such, may not realise the subtle difference in the names and think the syntax demonstrated applies for destructors and not deconstructors! In fact, destructors are not even covered which makes it even less obvious that there is a difference!
Constructors and deconstructors are about turning variables into a class and turning classes into variables, so I thought they fitted together. I've rarely seen *destructors* actually used so didn't bother including them.
sounds more of a clickbait-y crash course than a comprehensive list of every single feature the language has (which would be believable if the video was around 2 days long)
I found the grouping of constructors and deconstructors a little weird. First off almost nobody writes deconstruct by hand, and secondly when people think of the pair of construction they usually think of dispose or finalisers, for cleaning up, rather than how to explode the type.
Some of these features will only be for later versions. C# is a very mature language that is currently on the 11th iteration, so no, many of these features would not have been present in version 1.
2:58 false claim, classes can have methods that are less restrictive that their classes, eg. private classes can have public methods and internal classes can have public methods.
@@traintocode As a person who has experience teaching programming, whenever I have a short timespan to teach programming, I introduce the paradigm, then I introduce the type system, then functions and collections, then other runtime/paradigm features. I will start my C# video like this: a sophisticated oop language that is like C++ having Java syntax. There are six major types under a C# namespace that can be used to create objects. Value types like structs, enums...numbers, boolean are struct types. Reference types like class, records, delegates, interfaces. Then you talk about functions and how they work in each or all types and what those functions do, access modifiers, return, generators, generics, coroutines, out, ref, varags, events, anonymous functions. This will make the bulk of the video. Then collections: arrays, lists, linkedlists, dictionaries, sets, stacks, queues. Finally, if necessary the compilation and runtime directives like control flow, threads, using keyword, exceptions, macros, unsafe code... And it is done...
Static functions guarantee that the function does not depend on instance variables in a class and they can make functional programming styles a bit easier to stick to.
Watched the vid twice. so has been 20 mins. I should be a double C# expert by now but I still can't even write a hello world! I THINK I JUST GOT SCAMMED!
0:38 "arguments" when you are pointing to parameters? 0:58 "These days C# programmers will exclusively use var everywhere", sure maybe the bad ones. "Implicit typing is good so use it", if you're a bad programmer. 1:44 "am i a joke to you" -enums
Just a note for all the viewers. Records do not necessarily have to be declared "record MyRecord(string prop1, int prop1);". They can be also be declared with curly brackets in the same syntax as classes and structs. The syntax above is called a "primary constructor". It basically writes the property declarations and constructor initializations for you. Records were the first feature to have this and it's idiomatic to always write them like this but as of C# 12 you can use primary constructors on classes and structs too
do not use var, we look down on auto practices. The thought process is var is fine until you submit for the pr, at that point your variables should be very specific and not be allowed to auto cast
Everybody has their own preferences, if you agree as a team you don't want to use var then fine. Many developers find it makes the code more legible and 99% of the time you don't need to know exactly what type a variable is at first sight.
Yes, I'll use var if it's the project convention, but generally it's best to be specific/explicit of your intent. It tends to reduce bugs in the long run. Var is useful when you want to handle a type more generically, where you can minimize refactoring by having the type inferred. However, I'm not a fun of wholesale recommending its use.
You lost me as soon as you mentioned class. This is so far removed from vb6, pascal or even traditional C. Is it so wrong that some people just want to write simple programs without all this high brow theory?
I have used C# for roughly 5 years now, and I still learned something new!
Thanks! It is a very feature-rich language, more than most
Never too late to learn the "if" statement
I've been using it for years too, I had no idea of the newer stuff they added such as the functional switch statement, that's cool!
Same here, I don't know modern .NET 8...maybe it's 9 by the time I write this code though often times, so much to learn.
the > in the switch was mindblowing actually, 3+ years coding c# and never knew about that
I've been programming in C# since 2006, and this video had a few things I had forgotten. Thanks.
that record type, wtf, also the deconstructor, never used one lol
@@nihil_._sum here since 2016, never even seen one of those.
teach my my friend
Love this, great job. I'm an experienced programmer in other languages (C, C++, Java, etc.) and this is just the right level for me - not too little, not too much, perfect pace. It's great to have a quick survey, and when I need more detail I'd rather drill down into a written manual anyway than watch a video. Thanks!
you missed tuples, anonymous types, lambdas, exception handling, goto, LINQ operators like select, where, join ..., nested templates, virtual, polymorphism, RTTI, dynamic, default values, params, out, in, ref, const, enum, Lazy, IDisposable, garbage collection, lock, parallel... the list is much longer. But still a good video to get an overview.
I'm learning C# as another language after Python and this video was exactly what I was looking for, thanks
This is definitely one of the most concise, loaded with information video I’ve encountered so far about C#!!
Thank you for making this amazing video!
thanks!
The best ten minutes of education I've had in a while.
wow thanks that means so much!!
I agree
6:55 It´s important to mention that the using keyword in C# does NOT include the entire System.Collection.Generic but just makes it easier to type collection type in that file. Like instead of having to write System.Collection.Generic.Dictionary myDictionary = new System.Collection.Generic.Dictionary(); we can ommit System.Collection and just write Dictionary myDictionary = new Dictionary(); instead.
That is a good point thanks
@@traintocodeyeah using System; ≠ using system.Drawing;
I've been working with C# for 1 year and the experience has been very smooth. Also, great video!
best vid i've watched so far to help me switch from java to c#, thanks for brilliant animations and succinct delivery!
Man, Everything Else is better than this Ancient Mess called JAVA! Good Luck!
ive been using c# for a long time and searched for features i havent learned, 5mins in here and id better get these noted. excellent job.
It's the kind of video, that should be made for all other languages. Perfect set of features and timing! Thank you!
Thanks will do soon
Man you are awesome within 10 minutes you have covered lot of things. Thanks dude.
I am a javascript/typescript developer exploring other tech and I learned a lot today from a single video. Thanks!
very nice, I have been using C# for 15 years, read books, watched other videos etc. yet this is really useful and educational in just a short video. Thank you !
Glad it was helpful!
I didn't know there is a deconstruct method.. Learnt it here. Thanks.
Actually a very good presentation. Pls do it in the same manner on different languages
And even this video did not include all of it by far. But nice to see someone fit this much in 10 minutes.
I can only view this video as someone that knows C#, but I can say it was really good on catching me back up. It's been 3 months since I last coded and I feel I'm pretty back up to speed. Of course this is only general stuff. But it's a good start to learning/remembering.
Thanks, helped me a lot to get an overview!
Very nice. Especially nice if you already program in another language and want to see how C# does things differently.
Thanks for the video.
Great refresher of C# for me.
Glad it was helpful!
Some error in the narration: of course you can have public methods on private classes. That makes perfect sense. You really have to correct this error as it is quite important.
Great Video! Congratulations!!!🎉🎉🎉
Awesome man you taught alot to me in 5 mins coz i saw it in x2 speed ... KEEP IT UP MAN
I talk dead fast if you put me in 2x speed that would be impressive
I have met a lot, really a lot, of people who would say the opposite of what you did in regard to implicit typing.^^
Thank you for all this information.
Will you please cover the latest language keywords and features of C# version 12? Thanks. You are really rock!
> these days C# developers will almost exclusively use var
That's a very dangerous thing to say seeing all the heated discussions that come up everywhere once you say you either want var only, concrete only, or even a mix
You used both Destructor and Deconstructor terms for showing Deconstructors, only a small error but Destructors are vastly different from Deconstructors!
Aside from that, cool video. I genuinely think this is a good overview!
Brilliant. Thank you for this.
No worries!
Love the video, if you can have another one 10-15 minutes with Events, delegates , or API just simple as this fast and to the point.
I will do a follow up at some point there is LOADS I didn't cover. C# is a huge language.
better than many courses
이 영상으로 ^o^ 인해 새로운 동기부여를 얻었습니다.
I'm just starting to learn C# and wow....I have a lot to learn.
Very informative. Thanks!
I very much disagree with what you say about `var` and implicitly typed variables at around 0:55. You make the very bold claim that implicit typing is good without any support of that claim.
Implicit typing is a tool, and just like all tools, there are good and bad ways to use it; situations that call for the tool and situation that said tool should be kept far away from.
Implicit typing should be used when, and only when, the inferred type is obvious to the reader and should be. If the inferred type is in any way obscured or non-obvious to the reader (for example, when storing the return value from a method or property in another class), the variable type should be explicitly declared. Note I said the reader, not the compiler and not the author. Just because the type is obvious to the author at the time of writing does not mean it will be obvious anyone else or to the author at a later time.
Ultimately it is all about legibility. Our code must be legible; illegible code is difficult to maintain and modify. Implicit typing is a tool to make writing code easier, but ease of reading always needs to take priority over ease of writing if the code is to have any longevity.
amen
Most C# does still use var, and there are good things about it, like reduced refactoring at the caller if a type changes. The reason it's generally still readable is that the IDE is good at providing the type information.
That said it's starting to move back away from var in some places, with nullable reference types and the new keyword e.g. T t = new();
> You make a very bold claim that...
> Proceeds to make a very bold claim as well...
> Internet.
@@diadetediotedio6918 You left out the "without any support of that claim"-portion in the original post. OP however did have a support for his claim of drawbacks of using var. Whether you agree it or not is different topic.
@@ManWithoutThePants
No? He never put any support on his claim, that's why I made my comment. His claim was purely based on his personal opinion on the subject, which it is pretty easy to understand that the sir making the video also have.
very informative, thanks
awesome just what I needed to refresh it
Very useful, thanks! Exactly what I was looking for.
var value = 55;
var result = value switch
{
1 => "one",
2 => "two",
3 => "three",
_ when value > 10 => "greater than 10",
_ => "unknown"
};
Console.WriteLine(result);
That's one of the statements I didn't know, despite using C# for more than half a decade
I enjoyed this ;)
thanks!
@traintocode you are like brackeys' successor
Huge thanks ❤
I think it's not clear that Deconstruct are not a Destructor in C#.
Is a good video. :)
C# is a bit confusing for me because I've worked with C++ but never worked with OOP much, other than simple game scripting in C++
This video just gives a very quick overview of some of the functions of C#, but not all... THanks, but it was tough to follow for me.
What if you have a mutable type in a record, like an array? I assume you can change that?
Asking as a functional programmer.
Interesting about the => notation. Is there no final / const keyword? Is that to take the place of final / const?
That's rather unusual that instead of returning a tuple of values, the deconstructor actually includes the values in the parameters.
How does that work if you don't care about one of the values?
I find the PascalCase / CamelCase a bit off-putting, as I do the C-style convention of putting the opening brace on its own line... it just takes up so many more lines of code than putting it on the line where the class / method / etc. is declared.
Can methods be declared with a var return type to have auto type deduction?
How in-depth is the pattern-matching? Again, as a primarily functional programmer, some languages have really amazing pattern matching abilities.
Don't worry about answering these... it's just me thinking out loud.
This was an awesome video. I just got the Functional Programming in C# 2nd ed book from Manning to jump in feet first, but having never really used C# before (although knowing Java, Kotlin, and Scala well), this has been a really handy introduction to cover the basics that may well get me up to speed to the point where I can read the book without needing to go through a beginner text. And yes to Rider! I love me some JetBrains and buy the yearly subscription. CLion is the only C++ IDE that I can not only tolerate, but actually enjoy using.
This would make a good cheat sheet to download.
Thanks!
When I saw the title I already knew that it would not fulfill it's promise :D. Almost at every point I had something to complain. Though sometimes I might be a bit picky.
00:36 "Each line is ended with a semicolon". Well especially for new users of the language this can be misleading. Not every line has a semicolon at the end but every statement. It's a bit difficult to explain this in easy terms, though it's certainly not every line. Common beginner mistakes is putting a semicolon at the end of an if statement which would end the statement right there. So the following body has no connection to the if statement this way.
00:46 Besides line comments, there are multi-line comments using /* This is a comment */
01:26 Just like to point out that the primitive type list is a bit longer than what was shown here ^^
01:39 Well, he said DATA-types so we might forgive missing enums, delegates, interfaces and closures.
02:01 This is a common misconception. Structs don't live on the stack unless their variable is declared on the stack. Structs are value type and as such are directly stored in the memory of the variable itself. So it depends on where the variable is stored. When the variable is a field of a class, that struct would live on the heap.
03:00 This is just false. A private class can of course have a public field or method. How would you interact with anything in that class? When a nested class is declared private, it can only be used inside that class and can never be exposed to the outside. So you can not declare a public or ptotected field of your private class type since from the outside or a derived class, that nested class would not be visible. However the fields and method inside the private class can have the full spectrum of modifiers
05:20 Those unfamiliar with C# probably should know about logical and, or, xor and not operators which are &&, ||, ^ and ! respectively. Personally I get some itching when tutorials show boolean variables inside an if statement compared to true. An if statement simply requires a boolean value. Those logical operators will return / produce a boolean expression. However a comparison with true is completely unnecessary. You could also do if (aBoolVar == true == true == true) which does the same as if (aBoolVar). The comparison of boolean operators don't need to be used inside an if statement. You can also use them to assign a boolean value. bool myVar = someString == "Hello" && age > 18;
05:57 This is called a "switch expression" which actually evaluates to a value. A switch statement is actually a control flow statement which does not evaluate to anything, like an if statement or for loop.
06:49 Even though I don't like them because they have a lot of overhead, it should be mentioned that you can have multidimensional arrays as well. They may look useful, but the performance isn't that great. For every access it has to do a bounds check on each dimension / index and calculates the flattened index every time. In most cases, especially in time critical situations (when you create games and not business apps) just using a normal 1d array and calculating the index yourself can be way faster as you usually would use nested for loops and you can pre calculate some of the offsets in the outer loops. Also when it's a 1d array it's much easier to iterate over all elements regardless their spatial relationship.
06:55 Small mistake here. The System.Collections namespace does only contain the untyped / object variants of those collections. All the types shown there are inside the System.Collections.Generic namespace. You almost never want to use the untyped variants. They are essentially an ancient leftover. Even when you want to store System.Objects / objects, most people would still use the generic List with the type object rather than the ArrayList.
06:58 It should be pointed out that "importing" a namespace does not load anything like in other languages where some kind of import would actually load or embed another file. Such a using directive will "just" shorten the type names. So this is a pure organisational feature. We use namespaces to avoid name collisions. Different namespaces can have the same class / type names, but you can not "import" both as when you get a name collision, the compiler would complain as it can't tell which type you wanted to use. It's possible to "import" or resolve individual types by: using MyType = Some.NameSpace.MyType; Here we can even rename / give the type a file wide alias name
07.23 This is only partly true as the foreach loop does first and foremost use pattern matching and only resort to the IEnumerable interface when no pattern could be found. The pattern the compiler looks for is simply if the instance passed into the foreach has a method GetEnumerator and if the returned type has a MoveNext method that has no arguments and returns a bool, and it should have a Current property that is readable. If those conditions are met, the compiler will just use those methods, even without the interface. Most of the built-in collection types use struct enumerables / enumerators to avoid creating garbage on the heap.
07:34 Again, the generic version of the IEnumerable is in the System.Collections.Generic namespace. The untyped / object version is in the System.Collections namespace.
08:44 Just to use the right terminology, the stuff after the "where" keyword is called constraints. Several constraints can be specified by separating them with a comma. Note that all constraints need to be satisfied. If a generic class or method has more than 1 generic argument and you want to put constraints on more than one, you need to use another "where" for each argument you want to constrain. Just as a warning: Generics can be quite useful, but are often misunderstood. Many want to use them like polymorphism, however generics are somewhat the opposite of that. While deriving from a base class keeps the data of the base class but allows to overwrite functionality, generics actually keep the functionality the same while being able to exchange the data the function works on. Bound generic classes are usually incompatible with each other. So a List and a List are two completely separate types. In rare cases there can be exceptions with the right conditions (covariance / contravariance) but that are really rare usecases.
08:55 Well a lot is missing for it to be a video about all language features ^^. I know it can't really be comprehensive, but things that weren't really mentioned are:
delegates (essentially typed function pointers),
anonymous methods / closures, (ability to automatically capture variables in a scope object)
lambda expressions,
enums,
nameof,
all operators (there are a lot)
operator overloading in classes
type conversion operators
events,
CIL and the ability to decompile to other .NET languages
extention methods,
linq (I mean the LINQ syntax which is simlar to SQL, not the classes from the System.Linq namespace),
attributes (essentially static metadata that can be attached to almost everything)
params (essentially allows variable arguments as the last parameter of a method)
exceptions (try / catch / finally)
object initializer
nullable types
partial type declarations
ref / out (pass by reference)
indexer (allows a class to be used like an array or dictionary)
using statement (not to be confused with the using directive at the top. It's used to automatically dispose objects)
goto (Yes, C# has goto. Now forget that I mentioned it ^^)
reflection
Those are just some things of the top of my head. I only focused on language feautes, not framework features or classes.
Now I've spend already too much time on this post so lets wrap it up. There's still a lot missing. If you want to learn more about the syntax, look up "C Sharp syntax" on wikipedia.
I love C#. Keep them coming, just subscribed.
Thanks!
Do we have an Enum with a wrap value in C#? (I like the one we have in Swift)
enums in C# are just a group of constants, usually integers. Color.Red=1, Green=2, Blue=3 etc. They don't wrap values like enums in some other languages like Rust. You can do that, just not with enums.
Simply Beautiful
Thank you! 😊
What about events, actions, tuple...? :)
Goddam, I thought C# was going to be this whole thing, like learning to speak Spanish. But a year later I realise the actual vocabulary and rules could fit on a single note page.
Wrapping your head around them and practising is the hard part.
Great simple and straight forward without wasting time +1 but you missed Delegates, Reflection and Extension methods.
Great point about delegates and extension methods I definitely missed those. Reflection I'd say is more a feature of .NET and not specifically part of the C# language spec. There might be uses of C# that don't support reflection. Maybe I'll do another video on features of .NET which can include all sort of things in the System namespace!
1:23 Why is implicitly typing things good?
The benefit of implicit typing is that it is easier to write, but you still get all the benefits of the static types. It's a matter of opinion though, do you prefer explicitly typed variables? Some people do
@@traintocode Basically you should do whatever your code guidelines say unless you're writing them.
I wanted to get oop principles ubder my skin to be capable truelly code anything. So I try to find language to made me truelly use it ( my first language, python, not really useful for that in my opinion). I choose java and C#. Because of this video i am going to focus only on C#. Thanks you.😊
5:19 lol "== true"
Bro missed private protected and protected internal accessabilities
Edit of important things you missed:
- custom indexers
- attributes
- source generators
- operator overloading
- reflection
- delegates
- unsafe with pointers
- expression trees
- enums
- Garbage Collector
Congrats you're almost at 1k subs🎉
Thanks! I just hit that 🎉 what a milestone thanks so much for your support!
@@traintocode Congrats 🎉
delegates and events seem like features that should be included :D
I've previously done javascript, but didn't understand to much and I want to go into c# :(
They aren't all that different fundamentally, good luck with C#
Not sure I understand SquareEach. Shouldn't it be "yield squared"?
Maybe I’m the only one here but I hate implicit typing with a passion. Why would I ever want to put a barrier up for knowing what type I’m dealing with?
It feels to me that except in a few situations where you could get different types being returned to you and this gives you an option for how to handle that, that I’m always better off making the effort to be explicit in my use of types as it’s far clearer to read?
The worst thing is that they ruined the var keyword with respect to nullable reference types. Instead of introducing a separate "var?" statement to be explicit about a variable being able to hold null, they caved in to some people who wanted var to just always be nullable. Now, technically every variable declared with "var" is nullable in a nullable reference type context and will display as such when you hover the mouse over it.
It's okay, you can hate it all you want, it does not makes what you say true. My point is that knowing the type should not be more important than adhering to the contracts you put in your code using the types, and I don't think this is much of a "barrier" as you can pretty much still see the types.
I think i have c# brainrot, i love c# i like it alot its the perfect mix between usefull and simple, the language syntax just makes sense yet you can still do performant things when usings spans and things alike
Usually constructors and *destructors* are introduced alongside each other and not constructors and deconstructors. For one, many have heard of constructors and destructors but few may have heard of deconstructors and, as such, may not realise the subtle difference in the names and think the syntax demonstrated applies for destructors and not deconstructors! In fact, destructors are not even covered which makes it even less obvious that there is a difference!
Constructors and deconstructors are about turning variables into a class and turning classes into variables, so I thought they fitted together. I've rarely seen *destructors* actually used so didn't bother including them.
You guys are cool!!!!
Pls do mire videos on c# vs code am stuck with it🤔
이 'ㅂ' 영상을 기다리고 있었습니다!
sounds more of a clickbait-y crash course than a comprehensive list of every single feature the language has (which would be believable if the video was around 2 days long)
It doesn't matter for me, it was exactly the kind of video I wanted. After many years not using C# I wanted to refresh my mind about its syntax
I actually found this useful knowing nothing about C# but a bit of other languages such as python or c/c++.
This was incredibly useful to me as all I wanted to know what all the features c# sharp. Before I delve into it more in depth.
Fantastic!
I got a little lost at 4:26
(This is a bookmark so I can come back to it after a full night's sleep)
Yeah I tried to do this really fast but maybe too fast sorry
@@traintocode it is ok. I am just doing this until I get tired and confused, then sleeping and trying again. I am also new to coding
I found the grouping of constructors and deconstructors a little weird.
First off almost nobody writes deconstruct by hand, and secondly when people think of the pair of construction they usually think of dispose or finalisers, for cleaning up, rather than how to explode the type.
This is for all c# versions ?
Some of these features will only be for later versions. C# is a very mature language that is currently on the 11th iteration, so no, many of these features would not have been present in version 1.
2:58 false claim, classes can have methods that are less restrictive that their classes, eg. private classes can have public methods and internal classes can have public methods.
You forgot unsafe code(C pointers), delegates, events, threads, threadpools, nullables, enums,
Yeah the title is a bit of a lie. C# has so many features.
@@traintocode As a person who has experience teaching programming, whenever I have a short timespan to teach programming, I introduce the paradigm, then I introduce the type system, then functions and collections, then other runtime/paradigm features.
I will start my C# video like this: a sophisticated oop language that is like C++ having Java syntax.
There are six major types under a C# namespace that can be used to create objects.
Value types like structs, enums...numbers, boolean are struct types.
Reference types like class, records, delegates, interfaces.
Then you talk about functions and how they work in each or all types and what those functions do, access modifiers, return, generators, generics, coroutines, out, ref, varags, events, anonymous functions. This will make the bulk of the video.
Then collections: arrays, lists, linkedlists, dictionaries, sets, stacks, queues.
Finally, if necessary the compilation and runtime directives like control flow, threads, using keyword, exceptions, macros, unsafe code...
And it is done...
It's somehow just so simple compared to Python or Javascript, don't know why, just reads really naturally.
this is gold
Ok. So, why would you want a static function?
Static functions guarantee that the function does not depend on instance variables in a class and they can make functional programming styles a bit easier to stick to.
it should be remaked whenever new version released!
🌷💐🥀 شكرا جزيلا🌻🌼💐
Beautiful brief.
Watched the vid twice. so has been 20 mins. I should be a double C# expert by now but I still can't even write a hello world! I THINK I JUST GOT SCAMMED!
한국 ㅠㅠ 인 어디 없나요?! 자랑하고 싶은 마음이 몇 배가 됩니다~~
Didn't mention the all-important Lambdas but showed a bit of their syntax without saying what they were...
Sorry I was just trying to keep this fast C# has a LOT of features
lets make a new video on .. c# version 1 to 13.. all features
That would take all day 😆
0:38 "arguments" when you are pointing to parameters?
0:58 "These days C# programmers will exclusively use var everywhere", sure maybe the bad ones. "Implicit typing is good so use it", if you're a bad programmer.
1:44 "am i a joke to you" -enums
foreach loop ?????
C# has become too big, dumped it for GO and I will never look back 🥰
Go is a very streamlined language, something C# certainly is not! They are both great
Inumewable awway uWu
🎉🎉🎉
Why C# is more complicated that C++ ?
is it?
"Every", and proceeds to list about a 2% of features
Just a note for all the viewers. Records do not necessarily have to be declared "record MyRecord(string prop1, int prop1);".
They can be also be declared with curly brackets in the same syntax as classes and structs. The syntax above is called a "primary constructor". It basically writes the property declarations and constructor initializations for you. Records were the first feature to have this and it's idiomatic to always write them like this but as of C# 12 you can use primary constructors on classes and structs too
This is true - I actually made another video about primary constructors for classes here ua-cam.com/video/VarE4d2BqMo/v-deo.html
이 ㄱㅅㄱㅅ 런 기술이라면 나도 할 수 있겠다는 생각이 듭니다.
I hate var. its such a stupid thing to do and just makes it that little bit harder for someone else to glance at your code and know what is going on.
Really!!
I would just expect this message from an entry level .Net developer!
do not use var, we look down on auto practices. The thought process is var is fine until you submit for the pr, at that point your variables should be very specific and not be allowed to auto cast
Everybody has their own preferences, if you agree as a team you don't want to use var then fine. Many developers find it makes the code more legible and 99% of the time you don't need to know exactly what type a variable is at first sight.
Yes, I'll use var if it's the project convention, but generally it's best to be specific/explicit of your intent. It tends to reduce bugs in the long run. Var is useful when you want to handle a type more generically, where you can minimize refactoring by having the type inferred. However, I'm not a fun of wholesale recommending its use.
you're talking to other programmers only, inexperienced people get lost on those comparisons and references.
I had to condense everything to 10 minutes so a lot of prior knowledge is assumed yeah
don't do vars kids.
why?
@@traintocode its bad and addictive. c# is strongly typed for a reason. For everyone's sake, just write the damn type lol.
there is stupid feature called garbage collector
You lost me as soon as you mentioned class. This is so far removed from vb6, pascal or even traditional C. Is it so wrong that some people just want to write simple programs without all this high brow theory?
It's a lot like java. Maybe too much like Java
That's not every feature.