Тёмный

Deconstructor Updates in C# 10 and .NET 6 In 10 Minutes or Less 

IAmTimCorey
Подписаться 421 тыс.
Просмотров 37 тыс.
50% 1

Опубликовано:

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 134   
@reodanoe-jankolar1410
@reodanoe-jankolar1410 2 года назад
Random tip: You can exchange value between 2 variables without setting one of the values aside by doing this int a = 2; int b = 4; (b, a) = (a, b); a will then be 4 and b 2 Instead of int a = 2; int b = 4; int c = a; a = b; b = c;
@IAmTimCorey
@IAmTimCorey 2 года назад
Yep. While it shouldn't be, that might be an interview question.
@somebodyoulove
@somebodyoulove 2 года назад
Oh nice.
@matthiasauswoger7994
@matthiasauswoger7994 2 года назад
Yes, but thats not new in C#10, that worked before already.
@reodanoe-jankolar1410
@reodanoe-jankolar1410 2 года назад
@@matthiasauswoger7994 That's true, I've mentioned it because it's "similar" to what's been shown in the video.
@Roanoked
@Roanoked 2 года назад
listenig to this series while shaving
@IAmTimCorey
@IAmTimCorey 2 года назад
Great!
@baka_baca
@baka_baca 2 года назад
I'm really liking these short videos!
@IAmTimCorey
@IAmTimCorey 2 года назад
Great!
@sjogan
@sjogan 2 года назад
me too
@micro2743
@micro2743 2 года назад
Really loving this format!
@IAmTimCorey
@IAmTimCorey 2 года назад
Great!
@tuppas
@tuppas 2 года назад
C# is getting more and more awesome. I like the effort that Microsoft is putting on this programing language
@IAmTimCorey
@IAmTimCorey 2 года назад
Me too.
@tuppas
@tuppas 2 года назад
Are you going to do a class on AI? I would like to learn on that
@tuppas
@tuppas 2 года назад
Btw I learned to program, thanks to your videos. On the past they used to be a boring 2 hrs videos, but little by little I noticed that the way you explain things are unique and very useful. Thank Mr Cory for you dedication on this
@IAmTimCorey
@IAmTimCorey 2 года назад
I probably won't be doing a course on AI simply because of how complex it is. It isn't "normal" programming - higher-level math is heavily involved.
@moin_uddin
@moin_uddin 2 года назад
never seen it till now! again thanks for increasing my knowledge
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@shadowthehedgehog2727
@shadowthehedgehog2727 2 года назад
Looking more like JavaScript with this feature
@IAmTimCorey
@IAmTimCorey 2 года назад
Good features do tend to make it to other languages.
@psdmaniac
@psdmaniac 2 года назад
I think it was not a complement. And I agree with that. JS is the king of bad patterns, lazy written features (undefined this, inheritance etc) and bad written code. Is that because JS is most used by students, freelancers who don't have team or someone with development knowladge or just people who just started programming. Later those bad patterns starts to spread and became somthing normal across JS community.
@IAmTimCorey
@IAmTimCorey 2 года назад
Nah, this isn't that. This is an update that specifically makes our code better and simpler.
@haroldpepete
@haroldpepete 2 года назад
it really interesting, c# evolution goes fast, it incorporate Ruby and Python features
@IAmTimCorey
@IAmTimCorey 2 года назад
Great features from one language end up in other languages.
@psdmaniac
@psdmaniac 2 года назад
1.Thank you for the video. 2. I get feeling that c# is becaming over complicated. Like c++. The feature shown in the video is not very useful at least maybe for someone who like to use anonymous types and to write code that is hard to read and maintenance. I like KISS principle and in my opinion Microsoft is going in bad direction.
@IAmTimCorey
@IAmTimCorey 2 года назад
I'm not sure how this makes things harder, though. You don't have to use this if you don't want. However, returning Tuples from methods is a pretty common thing to do when you don't need a full class (and the added complexity) to return multiple values. Tuples actually reduce complexity. So now being able to declare our Tuple to return in a way that makes better sense for the situation actually makes our code simpler as well. For instance, let's say you have a method called ValidateAddress that takes in a streetAddress property. We could pass in an address like "123 sesame st". The goal of the method would be to properly format the street address and then let the user know if it is a valid street address. You could do the following: 1) Update the streetAddress variable to be capitalized and change "st" to "Street" 2) Look up the formatted address to see if there is a match in the database. 3) Output data = (validatedStreetAddress, bool isValid) output = (streetAddress, true); You just made your return simpler (no "out" variables and you mixed the inline declaration with the existing value). You don't have to use this but as you can see, in this scenario, the new changes actually conform to KISS.
@michaelschneider603
@michaelschneider603 2 года назад
@@IAmTimCorey As a long-time Java developer, I agree that multi-value results from methods are quite common and their handling can be a pain in the a** in Java - therefore I really appreciate the tuple feature in C#. And I also have programmed in Haskell for a number of years during the 90s, where tuples and decomposition/pattern-matching is used all the time, and considered clean and good practice.
@conaxlearn8566
@conaxlearn8566 2 года назад
I feel that eventually either JavaScript will replace C#, or C# will replace JavaScript. 🤣
@IAmTimCorey
@IAmTimCorey 2 года назад
I don't think so. There is room for both and we want both. Having only one option is not a good thing.
@digitalman2112
@digitalman2112 2 года назад
Getting more like Python all the time. Am a C# dev by day but love Python too.
@IAmTimCorey
@IAmTimCorey 2 года назад
Good features do tend to make it to other languages.
@TheSleepyCraftsman
@TheSleepyCraftsman 2 года назад
So what's your hot take on the hot reload controversy?
@IAmTimCorey
@IAmTimCorey 2 года назад
I’ll be doing a video on that but I’m hoping to have more to talk about when I do. People are working on it and I want to give them time.
@Frozen14boy
@Frozen14boy 2 года назад
Can you deconstruct just a part? So in a tuple with 3 keys, get only 2? Can you deconstruct directly to method params? I'll take a look after but those are my questions after viewing the vídeo.
@IAmTimCorey
@IAmTimCorey 2 года назад
Yep. Use an underscore for the items you don’t want. It is called a discard character.
@DarrenJohn10X
@DarrenJohn10X 4 месяца назад
So (Csharp, TupleDestructuring) = {JavaScript: ObjectDestructuring} Pretty much?
@tosinakinyemi3948
@tosinakinyemi3948 2 года назад
Precise, concise and insightful. Thanks Tim
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@muhammedalikhan7559
@muhammedalikhan7559 2 года назад
Love it that you have shortened your videos. Excellent tool to learn on the go.
@IAmTimCorey
@IAmTimCorey 2 года назад
I haven't shortened my videos. This is a new series with a different focus. Monday videos will still be the long format, which is best for learning a topic fully. This series is about having a quick reference to a specific thing.
@michaelschneider603
@michaelschneider603 2 года назад
Tried this recently in a unit test, where (in a SetUp method) I called some helper method that returned a tuple, and where I wanted one of the tuple components to go into a field (part of the test fixture), whereas I wanted the other component to be stored in a fresh variable to be used only within the SetUp method. There are a couple of more minor language features that may not be widely used in production code, but can come quite handy within tests. This may be one of those.
@IAmTimCorey
@IAmTimCorey 2 года назад
Great!
@dirkp.6181
@dirkp.6181 Год назад
It can perhaps also shine in functional approaches. Btw, besides simple types, what about using lambdas in tuples?!
@vuhoangdung
@vuhoangdung 2 года назад
this is getting more and more like F# 😅and that's a good thing
@IAmTimCorey
@IAmTimCorey 2 года назад
Good features do tend to make it to other languages.
@NAEL4SLR
@NAEL4SLR 2 года назад
I love those new 10 minute series !
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks!
@ravivarmavelukonda
@ravivarmavelukonda 2 года назад
Can we c# is borrowing or inspired from modern JavaScript? All the new c# 9 or 10 features already exists in JavaScript.
@IAmTimCorey
@IAmTimCorey 2 года назад
All languages are inspired by features from other languages. They also learn from the mistakes of others.
@prasadhonrao
@prasadhonrao 2 года назад
So much influence of Python on C# language now
@Any1SL
@Any1SL 2 года назад
Don't really care about the deconstruction but more of using ternary operator when returning tuples inside of classes which I believe is available in the new release
@Chess_Improvement
@Chess_Improvement 2 года назад
thanks, any tips for randomize and random number.
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 2 года назад
What really is the purpose of a tuple? Is it similar to an anonymous object or another type of collection (similar to a list)?
@IAmTimCorey
@IAmTimCorey 2 года назад
The biggest value of a tuple is that you can return more than one value from a method without using an out parameter or creating a throw-away class.
@Skeiln
@Skeiln Год назад
I dont know so much about deconstructors, but this is not the same as a class deconstructor right? I always thought a deconstructor is to dispose? Or is that still something different from a destructor? Im confused! :D
@IAmTimCorey
@IAmTimCorey Год назад
A deconstructor isn't the same as disposable. A deconstructor breaks down an object into its parts. A dispose is used to properly close down any open resources before an object is destroyed.
@Skeiln
@Skeiln Год назад
@@IAmTimCorey Hey Tim, thanks for your answer. I have one more question if you don't mind, but, a deconstructor is not the same as a destructor? As far as I understand these are still 2 different things. I have not used any of this ever (yet), but it is def. some interesting stuff. Have a nice day!
@JerrodVolzka
@JerrodVolzka 2 года назад
IMO, not great. Abbreviated syntax does not always make the code more readable. Great Video Tim! I would know know what to think about this if not for you showing it to me so well. Please keep doing what you do for us!
@IAmTimCorey
@IAmTimCorey 2 года назад
Glad it was helpful!
@alexcosta2614
@alexcosta2614 2 года назад
You don't have to use everything. c# is taking cues from other languages which makes it easier to migrate from several languages.
@rickytm
@rickytm 2 года назад
It's like JS!!! Thanks for sharing and greetings from MX
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@AP-pz9wp
@AP-pz9wp 2 года назад
This is great but it would have been better if instead of parenthesis there was a bracket so Javascript objects could simply be plugged. Imagine being able to deconstruct a Javascript object expression in the fly.
@dato666
@dato666 2 года назад
I think mixing will be kinda confusing and make the code less readable
@crogon-yt
@crogon-yt 2 года назад
The naming is somewhat ambiguous no? This doesn't seem to have anything to do with a ~ClassName() deconstructor. 0_o
@IAmTimCorey
@IAmTimCorey 2 года назад
That’s a destructor.
@crogon-yt
@crogon-yt 2 года назад
@@IAmTimCorey ah right. hrrdrrr
@AndreasRavnestad
@AndreasRavnestad 2 года назад
Another random tip: You can use var in the deconstructor as well, like so: var person = (fn:"Tim", ln:"Corey"); (var fn, var ln) = person; If you _should_ do so is another story :)
@IAmTimCorey
@IAmTimCorey 2 года назад
True.
@metaltyphoon
@metaltyphoon 2 года назад
You can make it even shorter var (fn, ln) = person;
@AndreasRavnestad
@AndreasRavnestad 2 года назад
@@metaltyphoon Nice, I like that more :)
@Mythilt
@Mythilt 2 года назад
Saw the deconstructor in the title and thought it was a change to instance disposal.
@IAmTimCorey
@IAmTimCorey 2 года назад
Yep, Deconstructor and Destructor are close in name.
@jonuzmiftari8112
@jonuzmiftari8112 2 года назад
Short and clear. Thanks!
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@NathanaelCrapo
@NathanaelCrapo 2 года назад
I can see the appeal, itll probably be a while before i start using it
@IAmTimCorey
@IAmTimCorey 2 года назад
Sounds reasonable.
@belmiris1371
@belmiris1371 2 года назад
I have never used tuples. I misread your title as destructor s. I thought maybe MS would do something useful with them. Thanks!
@IAmTimCorey
@IAmTimCorey 2 года назад
Tuples can be really useful, especially for returning multiple values from a method without the need for a class.
@XuChunVideo
@XuChunVideo 2 года назад
what tools are you using? looks like it's not visual studio
@IAmTimCorey
@IAmTimCorey 2 года назад
It is Visual Studio 2022, which is needed for .NET 6 (at least to create the templates and for hot reload).
@sergeymigel4680
@sergeymigel4680 Год назад
thank you! good voice for understanding
@IAmTimCorey
@IAmTimCorey Год назад
You are welcome.
@SkrGta
@SkrGta 2 года назад
Is C# copying JS or is it the other way around 🤔
@IAmTimCorey
@IAmTimCorey 2 года назад
Good features from one language make it into other languages. That's the pattern of software development.
@SiegfriedFarnonMRCVS
@SiegfriedFarnonMRCVS 2 года назад
What is the IDE you're using? Haven't watched your videos in a while because they are too long. I prefer these 10 minute snippets. Much better. Thanks
@janne_kekalainen
@janne_kekalainen 2 года назад
He's using Visual Studio 2022 Preview in this video.
@IAmTimCorey
@IAmTimCorey 2 года назад
Yep, VS2022. You cannot create new .NET 6 projects in VS2019.
@bootsector13
@bootsector13 2 года назад
i really like short videos than 1hr videos that i can get sleepy easily lol. btw thanks for the new tips tim.
@IAmTimCorey
@IAmTimCorey 2 года назад
Glad you like them!
@goodoleme747
@goodoleme747 2 года назад
These vids are great btw
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks!
@eslips
@eslips 2 года назад
Looks like JavaScript deconstruction
@IAmTimCorey
@IAmTimCorey 2 года назад
Good features do tend to make it to other languages.
@eslips
@eslips 2 года назад
@@IAmTimCorey yes! Solidity has a very similar syntax as what you showed with Tuple in C# Tim, thank you for putting out such a great content. I have been watching you for more than 2 years now and your tutorials helped me personally a lot and also, helped me during in-office training sessions with my devs.
@kolesplace
@kolesplace 2 года назад
LOVE the 10m series.....
@IAmTimCorey
@IAmTimCorey 2 года назад
Great!
@kumar_codes
@kumar_codes 2 года назад
These short videos are very good...
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks!
@karimvtvtvtvvgvvvvakabery6025
@karimvtvtvtvvgvvvvakabery6025 2 года назад
Can i Decode json to Records?
@adds-kz3oc
@adds-kz3oc 2 года назад
You can do that just as you would with a normal class.
@swordblaster2596
@swordblaster2596 2 года назад
That deconstruction syntax is super non-intuitive. Another dubious feature from the school of "reducing the amount of text". Great job, less text that's even less clear in intent.
@IAmTimCorey
@IAmTimCorey 2 года назад
How else would you break apart a Tuple?
@swordblaster2596
@swordblaster2596 2 года назад
IMO - What's wrong with explicitly doing it for each element you care about? This syntax is yet more cryptic syntax that's in no way intuitive. I see code like this all the time where devs are excited to use some new syntax, at the cost of code readability. Every second I have to spend "ok, this is ACTUALLY doing XYZ" because someone thinks that 1 line of code is always inherently better than 2 or 3 lines of code is wasted time.
@swordblaster2596
@swordblaster2596 2 года назад
Totally disagree
@somebodyoulove
@somebodyoulove 2 года назад
Nice video. Thanks for the post.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@dosomething3
@dosomething3 2 года назад
I stay away from tuples.
@IAmTimCorey
@IAmTimCorey 2 года назад
Why? They cut down on the overhead of a class and can still be named. They eliminate the need for ref parameters in methods too.
@jessyxenon3647
@jessyxenon3647 2 года назад
good tip ,really time saving,more on that :)
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks!
@iammachine1
@iammachine1 2 года назад
nice feature, thank you!
@IAmTimCorey
@IAmTimCorey 2 года назад
Glad you like it!
@user-kt7nd6pg1p3
@user-kt7nd6pg1p3 Год назад
Thanks for this
@IAmTimCorey
@IAmTimCorey Год назад
You are welcome.
@metaltyphoon
@metaltyphoon 2 года назад
When can we hear you thoughts over the debacle of removing hot reload from dotnet watch , or the possibility of removing dotnet watch entirely from the SDK to keep it behind a VS license ?
@IAmTimCorey
@IAmTimCorey 2 года назад
I'm waiting for an upcoming announcement before I do a video on the situation. Right now, it isn't good, but there is hope that this will be reversed. Remember that the .NET team is not behind this. This is a management decision that they don't like either. I'll definitely be doing a video on it soon, though, even if we don't hear from Microsoft.
@metaltyphoon
@metaltyphoon 2 года назад
@@IAmTimCorey Peace has been restored!!! But some damage had been done.
@IAmTimCorey
@IAmTimCorey 2 года назад
My take on it launches Sunday morning.
@UmanPC
@UmanPC 2 года назад
Interesting
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks for watching.
@DaNoob_777
@DaNoob_777 2 года назад
Thanks!
@IAmTimCorey
@IAmTimCorey 2 года назад
Thank you!
@kishor4900
@kishor4900 2 года назад
Don't you think 🤔 c# just copying js features . Like string interpolation and destructuring ...
@IAmTimCorey
@IAmTimCorey 2 года назад
I did a whole video about that: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-83CTq_Fg5Xc.html
@m1sha2004
@m1sha2004 2 года назад
Nice short tips, thx
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@roelbrook7559
@roelbrook7559 2 года назад
With a title mentioning "Deconstructor" I immediately thought; doesn't C# call that a finalizer? Also, as your example is using string, it actually makes no difference that you can re associate to an existing variable. Strings are immutable, so the assignment would create a new instance anyway.
@IAmTimCorey
@IAmTimCorey 2 года назад
That isn't the point. The point is that we don't need to have a new variable name. Sure, behind the scenes there is a new string created either way but now we don't have a new variable and assignment just to properly fill the tuple.
@michaelschneider603
@michaelschneider603 2 года назад
@Roel I think what you mean is called a "destructor", not "de-con-structor". C# offers special syntax for the object finalizer (a .NET feature), the same "~CLASSNAME()" syntax as in C++. This is completely unrelated to the feature presented here.
@root317
@root317 2 года назад
No views o.o
@IAmTimCorey
@IAmTimCorey 2 года назад
You got in right at the beginning.
@root317
@root317 2 года назад
@Jack Ferghana ikr i just was too happy cuz I've never been that early :D
Далее
#kikakim
00:10
Просмотров 13 млн
Stop Using FirstOrDefault in .NET! | Code Cop #021
12:54
Implicit Usings in .NET 6 In 10 Minutes or Less
8:41
Primary Constructors in .NET 8
28:42
Просмотров 23 тыс.
Intro to Tuples in C# In 10 Minutes or Less
9:50
Просмотров 41 тыс.
Every feature added in C# 10 with examples
15:59
Просмотров 125 тыс.
Binary in C#: Binary Basics in 10 minutes or less.
9:24
IDisposable and Finalizers
23:00
Просмотров 22 тыс.
Every single feature of C# in 10 minutes
9:50
Просмотров 133 тыс.
The weirdest way to loop in C# is also the fastest
12:55