Learn C# with CSharpFritz - Ep 3: C# Methods, Events, and Delegates for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey there good morning good afternoon good evening whatever time it might be where you are welcome back to the visual studio channel my name is jeff fritz and this this is c sharp with c sharp fritz episode three how's it going there chat room so good to see you welcome back oh my goodness i'm i'm looking around look at how nice and sunny it is outside oh my goodness as i look outside it's a wonderful day here how you doing there chat room let's take a look at the chat room good morning to you eternal dev coder viral flows says good morning good evening and good afternoon well it's good to see you lap hurt welcome in shy sharp good afternoon to you out there is that phone my att att good evening to you smartcod hello makerslab hello to you vadler mufan is that mufana blue you're ready for it you're ready are you sure double check do we have all the things is it is it all here hang on i've i've got my surface dial yeah yeah we're ready okay we got it everything's dialed in there so good to see you how's it going uh i'm good look oh my gosh phone my atm t i i don't this is a face for radio okay i will work on that cymac good morning good afternoon to you kevin q anderson trying to execute the hat command get a little hat identification this is um this is a a hat from penn state university i went to pennsylvania state university uh right here in the east coast of the united states and um typically here inside uh the state of pennsylvania you'll hear folks refer to it as just state and they consequently have a a navy blue s sometimes as a logo that they use on secondary things today's the first day of class for those students at pennsylvania state university or penn state as we call it and a little sign off a little acknowledgement to those folks that are going to their first day of class back at university all the best to you students out there in your first day of the fall 2020 semester so we've we've had a couple of really good episodes here we've had some some good times learning about defining variables interacting with those variables using some basic operators and then we learned how to define our own types with classes and we went through and learned a little bit about class constructors and how to how to set up properties but let's get into doing a little bit more with actions inside of our classes in in today's session we're going to spend some time looking at methods we're going to talk about a a commonly i think misunderstood and underused feature called delegates we're even going to talk a little bit about anonymous methods and we're going to get into events to wrap up our session together so i hope you hope you buckle up i hope you're ready to enjoy a full session here together as always all of our demos all of our interactive samples are available for you right on our our github website there's a series of jupiter notebooks out there they're all out there they're always going to be there i'm going to post the link into twitch chat there for you and you can click through and run these in your browser whether you're on a tablet you're on a phone you're on a desktop a laptop doesn't matter what you're using you're gonna be able to participate and write some dot-net code along with us and i encourage you to open your browser and give give it a try because there's things that you may want to tinker with things you may want to explore and ask questions as we go along here if you're watching the recording out there on youtube sorry you missed all the fun but what i have done is i've linked all the questions that the folks in chat have had they're in the description just below if you click through you'll see links to every question that that we've had during this recording and for those of you that are watching this live all of your questions will pop up in the description just below the youtube video links right through so you can get to the question and maybe it's a question you have maybe there's something that you want to learn a little bit more about the ama tag is on here ask me anything about about c sharp a big out about we messed that one up about beginner topics in dot net that maybe you saw something in a previous video that you want to know more about that's okay ask your question we'll triage it and answer those as we go along here it's perfectly fine to stop and answer those questions this is not a pre-recorded course this is a talk show this is a format where we're going to discuss we're going to learn a little bit together and we're going to interact with folks in the chat room as we go along here all right let me head over to the code and we're going to get we're going to we're going to get some music playing in the background here as well because it's it's always a little bit of fun to have some code play have some code have some music playing that we can interact with that we can enjoy as we're going along this is music from um from our friend uh harris heller and this is from his synth wave playlist some groovy new wave techno music that we can listen to royalty free on on twitch on learn tv on youtube and everybody's welcome to listen and uh play it in the background of their streams thank you so much harris we appreciate you sharing your music the stream beats music with us you can find this out on spotify on youtube wherever fine mp3s are available is that a thing find mp3s i guess so here's our github repository i already linked it in chat if you're out there watching the recordings you're going to see it in the links just below github.com slash c sharp fritz slash c sharp with c sharp fritz there you go you see the repository right there in the corner that you can click through and and today like i said work this is session three if if you're watching this at some point in the future the repository may not look exactly like this but you will be able to click the launch binder button here to to launch and get over to the binder website where you're going to be able to use that jupiter notebook live and interact with it with it and follow along with our samples as i'm as i'm writing code as i'm talking and going through things here on stream all right um a couple questions that i well i see one question coming in from i play poker bedley now if you've seen me on my channel on the c fritz channel you know i talk to i play poker badly a lot and i play poker pretty okay but i play poker badly is here and and they have a question for us um let me bring this up and i'm going to queue up the next question here from egzy do you ever plan on doing a series on wpf wpf is the windows presentation foundation it's a user interface framework that we can use to to build applications that run on windows 10 windows 8 windows 7. i think it goes all the way back even to to windows um windows xp it'll work we'll consider this at some point after we get past some of the basics in c-sharp we're really focusing on the programming language we might come around to talk about this in november december time frame but definitely a consideration um do me a favor open an issue here in the repository and we can get some votes on that so that we can prioritize wpf maybe windows forms um maybe xamarin maybe you want to see a mobile app we'd like to build together and learn about that but the goal here is we're going to start with with c sharp the basics of the programming language and we'll move into some of the user some of the user interface uh frameworks a little bit later certainly when we get on the other side of net five dot net five is scheduled to be released in november 2020 if it's later than that you're watching this recording it's going to sound kind of weird that i'm saying that it's scheduled to be released sometime in the past but um it we may have a lot more options to talk about when we get on the other side and it'd be a little bit clearer how we pull those pieces together there is a another comment here a question from eggsy are there branches for each episode actually there's a notebook for each episode i create a branch as i'm working on each session and i i push in those branches as i complete them i merge them into it's still the master branch i need to rename that i prefer it to be main branch but you'll find under the notebooks folder you'll see here's all the samples for zero one this is the first season that we're doing this um and session one session two session three so we number them zero one zero well zero one and then the session number so at some point there might be a lot more in here if you're watching this recording at some point in the future there might be a ton in here and we're going to continue building this out as we add more um as we add more content and as we host more of these sessions um that's right aps twitch we're doing it live halfway through learning about the dot net conf micro services workshop very cool glad to hear that phone my att so much information in one video yes oh yes chock full feel free to pause go on high speed whatever you'd like to do slow things down that's the beauty of doing this on video is that you can interact with it and of course if you're watching the recording and you drop some comments below i'm happy to to follow up and answer your questions on the recording as well i think i need to turn up the music just a smidge yeah we're all right there okay so these are jupiter notebooks that we're using as part of this this helps to um it helps to run with net interactive that's an interactive version of net that you can build and not necessarily develop a full application but you can interact and execute some basic.net commands build some c-sharp constructs and interact with those i have this repository cloned locally you can do that as well and i have um i have my jupiter lab running locally so that i can see all of my notebooks inside this folder there's the folder from from github i can click into my notebooks and i can see these here if you're running on a um on a laptop or on a pc on a mac linux machine you can certainly clone these locally and run jupyter lab on your machine so you can have a more complete experience all right let's um let's start talking about session three i have all three tabs open from our previous two sessions and our current session that we're going to be working through together um is that john exum 77 has a question for us let me cue that up here good morning well good morning to you john um will this series go into xamarin at all and this is where i'm i'm kind of torn as to when we get on the other side of language features which user interface framework should we go into is it wpf is it xamarin and what's the order of those that we're going to touch on so i'm not opposed to it but i need to figure out what's the appropriate order so do me a favor open an issue over on in fact let's do this let's just jump right into it i'm going to come back over here into the github repository and let's add an issue here um user interface uh frameworks right um let's talk about a user interface next um but which one type correctly jeff so what i'm going to do is i'm going to put some comments here and you can vote on them so wpf windows forms uh xamarin for mobile applications and what you can do is you can react you can click the little smiley face and give it either either a thumbs up or a thumbs down maybe a cheer so that you can indicate which one which one do you want to work with um let's even throw in here asp.net core uh blazer so and let's just edit this quickly that is windows presentation foundation there we go i think that makes it a little clearer so let me know you can click through here you can like i said click on the little emote little smiley face give it a thumbs up thumbs down let me know where you'd like us to go next and we'll we'll use this to help prioritize what our next uh what our first user interface framework is that we're going to go into so i'm just going to mark this as a question there we go we already see somebody tagging wpf there so there you go um and we'll get into that later all right um that's right fund my att um jupiter lab does support c-sharp yep if you click through the github repository there's links to everything about how that works right here in the readme notebooks are built using.net interactive and that'll get you all the details about how this is configured um i see viral flows would like a demo of c sharp nine so here's here's the thing and here's i'm i'm actually going to purposely avoid c-sharp nine at the beginning sessions of this because c-sharp nine isn't ready yet so once once we're on the other side of c sharp nine being released we'll probably do a session of new c sharp nine features we may even bring a guest on to help introduce those features and talk through them here on stream um and let's even drop an issue about that and uh c sharp nine features um let's talk about the new features of c-sharp 9 as they are released with uh net 5. now this is in the future this is definitely a future show idea but it's much much further out um do i have milestones i don't think i have milestones no um i have a project listed here for august september sessions this isn't going to be until at least november so i'm going to create a another project here and i will call this um i will call this future sessions as a way to kind of put it out there as sometime in the future uh will be um evaluated and added um to the schedule when the next schedule is put together all right create that yep scheduled done there we go so i'm going to add over here no no no no no add a card c sharp 9 features we'll put that sometime out there all right so now this should say that it's on that project there it is fantastic so we will get there [Music] all right cool and if there's topics if there's things that you want to know more about questions that you might have please go into that issues tab go ahead and fill something out there no judgment always open and happy to review and answer any questions that are there um i should put a code of conduct in here um because any kind of bullying any kind of um nastiness we don't we don't want to tolerate um so let's add a code of conduct to the repository so um tell you what i'll even mark that as it's a documentation thing somebody's more than welcome to go in and submit a possible code of conduct for this and we can evaluate there's a couple of default ones out there there's a default one that we use for the.net repositories we may just grab that and bring it in here so all right let's start talking about our content today methods events and operators this is the second part of making your own classes that we did over here in session two so we're gonna make our own that should be types right it was making our own types so let's call this uh making our own right making our own or your own should be our look at that there we go making our own types methods events we don't get into operators delegates [Music] um so methods when we talk about methods methods are those things those code blocks that you put into your classes so that you can perform some sort of an action right you want to act and and either have have your class right a class is an object in c sharp and every everything in c sharp is an object well if we want to have our objects be able to do something or be able to do something to them we need to create methods so let's do that let's let's create a method let's create a signature let's create something that will let us that will let us act on those classes that'll let us have these action tasks go on okay i don't want to use the term task that'll let us have these this action code happen inside of our class now when we define a method a method has a signature and i even have a link to the official c-sharp documentation if you want to look at that but methods have a signature and you're going to have some access modifiers we learned about access modifiers like public and private and internal last time well you're going to have some number of access modifiers and by default if you don't include an access modifier it's it's considered private i should probably include that um by default um a method with no access modifiers is considered uh private okay um you then define your return type if there is one there oh and there there is one by default you can return void to indicate it doesn't return anything and a collection of parameters now parameters have a signature that are defined uh separated by commas and they have this signature that looks like the parameter type and then the name of the parameter so int my first parameter is a way for you to say my first parameter is an integer that we're going to receive and interact with inside this method how we doing chat room sound good so far all right chat room looks like they're doing cool they're just hanging in there and and having a good time listening to the music all right i also want to make sure that i welcome folks that are watching on learn tv if you're over there on learn tv it's so good to see you we're going to be ending at exactly 11 a.m because there's another show coming on right after this on learn tv so very cool to be participating with those folks as well all right so if we have let's go back to we started with this student class that we defined last time and i'm going to keep iterating on this student class i've got this c sharp code here that i dropped right into the notebook that we can take a look at so if we have a class named student we might have these methods that we can use to interact with the student we might have our student enroll and write some code that does enrollment inside of that block or maybe our student is leaving class early and and that's internal to our project you you must be a inside of our class library you must be inside of the interacting with the um the student class program right the program that this is housed within in order to leave class early so it's internal and we're going to pass in a date and time that says here's what time the student is leaving class right there's there's an input argument we're passing there maybe we want to calculate the grade for a specific class and we're going to pass in the name of the class uh and and there's a example calling it here calculate the grade for for the quantum physics class so right that's something that you may want to call right hey go calculate the grade for this student so that we can display that and and i just have it returning a faux value of 95 0.95 so right we can we we can exit our methods with the return statement like you see here in calculate grade for class and particularly if we have an output value in that case a decimal that we're returning a new a numeric type a real number type you have to provide a value that you're returning in the cases where we're where we are returning void we there isn't a value where we're returning from it we would have return and we don't need to provide a value that we're returning from the method so these are these are ways that we can set up basic methods now i see a couple a couple of questions here in the chat room um let me take a look over here and queue up two questions the first question we have here is from cookie z just joined to wonder if it's possible to download what we're showing here check out the github repository um code with sean link that but there's a github repository with all these and if you're watching the recording there's a link just below on youtube that'll take you right to the github repository so you can download the jupiter notebooks or you can click through there's even a link there so you can execute them on the binder website and run it live in your browser just like i am during today's session another question here from phone my att asking is it considered bad practices to use nested classes so i haven't i haven't shown this yet but you can put one class inside of another class it's not considered a bad practice but it can be tricky because you're going to start to see things that that create this object hierarchy that could be a little a little funny to navigate around um so i can certainly put another class inside of this class because it's it's another object i and i could create you know a class here called grades right maybe grade right and maybe there's a maybe there's a property here um name string name of class and this is maybe the name of the class that that we have a grade in right but we've been scored right here's here's how you did and i can then reference that grade class by saying var g equals new student dot grade right um and i can display g at that point and if i run that it right it looks a little weird come on because i've i right i've got i've got to say student grade and it's something that's inside of it now sometimes this makes sense if you want to kind of hide classes from top level interactions you want to create that hierarchy you can do that and and sometimes you'll see folks do this when there's um i've been using this particularly for data types that i'm returning from web services i want to make sure that i have a a very tight um [Music] a very tight payload of that data type i'm returning from wherever it might be i'm interacting with with an api somewhere out on the internet well i'll nest all my classes so that that payload message has all of its specific types inside of it right that way they don't get confused with other top level types so inside the same class is something that you can do but can get a little a little tricky to manage and you need to be um deliberate about how you interact with it in in this way by by nesting them like that right i'm kind of hiding them from other from outside construction right you actually have to reach in to go get it so um mr smoofy asks don't think i've ever seen a class in a class so you don't need the outer class created first to create the inner class that's correct you you can reach into and create that inner class in order to interact with it just like i did here with the new student grade interaction so um let's see here and um evan weeks i i completely agree with with this approach that evan is describing for project organization and and we discussed this last time most folks most net developers prefer a cs file per class and then use folders and name spaces to kind of group functionality absolutely that's a great way to organize things we haven't really talked about namespaces um but they're a way for you to to group up classes here and we'll see that as we get into an actual program um or a library but that'll be probably another few episodes down um but separate area we're using this to separate functionality or features i would only nest like this if these are very tightly coupled features okay so right if i'm bringing back here's information about a student inside of a message class from some api somewhere it may make sense to nest those types because you you don't want the the different ways that a student references their their person name their person demographics and and then their grade information that are specific to how you interact with that student record you may want those nested because they're explicitly appropriate just for that message that you're receiving so it's an option these are different design things that you can do as you work on and build code for your project thank you for the for the comment the consideration there evan um capparino too advanced not going to get into that um yes a tooth killer that's a that's another good point we can make these private classes inside of here and then you can't access it outside of it so you can hide some of the implementation details you can hide and make some of the interaction some of the implementation a little bit cleaner inside of here if there's business logic or something that you're doing that that is specific and it only should be done inside this class and you can prevent other parts of the program from being able to access that class so there's a good instance where you may want to make a class private now it works again so different ways that you can interact with them and and you can put classes inside of other classes now we're talking about methods and i want to make sure that you know that method access modifiers are right and these are the various scopes that you can define public protected we're going to see more about protected when we get to our episode about interfaces and abstract classes private internal and protected internal we've seen what private is doesn't allow outside of this ma this class to be interacted with internal lets you protect so that only inside this library inside this dll or executable can we actually execute that method protected internal is another one that's specific to some of the inheritance and object-oriented features and we'll cover that more in that object-oriented session later so in addition to providing parameters that are very clearly spelled out here like string date time right we can chain these together and there's the i call it the magic params parameter and optional parameters so check this out we can say for our student hey calculate the grade point average for a collection of classes i don't know how many parameters they're going to submit a number of these arguments it it could be however many it doesn't matter but go calculate them okay so i can pass in then as many different strings as i want here right i can pass in art class i can pass in uh i don't know english german class gym class um study study hall sure and it will accept and interact with all of them here now we haven't covered loops yet we'll cover loops i think it's going to be it might be next week that we cover loops um but i'm just doing an iterator across that collection and outputting and displaying what each one of them are so you can interact with and pass multiple arguments and just have it figure out what those are as we're going along here sure right this is a way for you to interact and and make that method a little bit more open-ended as to the arguments you pass into it now you can also overload you can overload methods just like we saw overloading constructors i can add and i didn't i don't think i put any information here about overloading um i'm going to need to add a section here about overloading let's um i will do i'll write some some text around that later but i can let me back up here i can overload this right and and provide other signatures for this so i can say public decimal uh calculate grade for class uh string class name um short short year enroll right because maybe maybe you're taking right different versions of this right i'm going to return some other value here doesn't matter what i'm returning but the idea is um i'm calculating grade for the class quantum physics but i can also calculate the grade for the class quantum physics when you took it back in 2019 and i'm calling the same method but passing a different set of parameters into it both signatures are valid and i'm able to interact with both methods independently of each other okay now if if we look down here there's also the ability to not just overload but we can have optional parameters now this is this gets a little bit tricky because now we can specify a default value to make that to make that parameter optional so if i specify calculate grade point average 2019 algebra history computer science it's going to go through calculating gpa for year whatever the enrollment year is and pass that information out but if i don't include this and i execute well it's looking for that optional value i can actually specify and say well these are these are my classes by providing a named argument here like so to kind of force the issue in this type of syntax and you see it picks up that it's still calculating for now that default year 2020 and stepping through and showing me all the classes that are specified now right if i had if i had made this a simpler method right um public decimal let's override that other one uh calculate grade point average i see the question in chat will come to that in just a second maybe i want to just calculate for all of my classes right i can easily specify it like that and right if i were to let me just copy this down you've got whatever your calculation is out somewhere else calculating gpa for all classes in the year right [Music] now now it gets a little bit a little bit funnier because i can also change this and say display s calculate breed point average and now calculating gpa for all classes in here let me make that a different output so that you can see that it's clearly different so i'm passing in different arguments and by not specifying an argument there it it drops down into being 20 20. i i can force that and say no we're going to calculate it for 2018 and it will take in 2018 and use that value so a couple different ways that you can interact and do like i said optional parameters there to interact with things all right i see a couple questions here in the chat man in chat let's bring those up and take a look um that looks like it's working well i'm gonna close that all right let's take a look um i see a question here from mufana blue i'll cue that up and visitronic and evan weeks let's let's take a look at each one of these questions so mufana blue asks when writing method it's a rule that they do one thing and one thing only it's not a rule but it's a good design pattern it's a good consideration when you're building a method if you have a method that does too many things it's going to get confusing when you try and figure out you try to debug them you try and interact with them so um there's there's one school of thought that that um i like to encourage junior developers to consider and that is your methods shouldn't have more than seven lines of code if they have more than seven lines they're doing too much so break that out and and put them into other methods so that you call them from a top level method and you can break them down right so um because these right these methods can call each other right i can i can certainly from inside of here um right i can certainly call uh calculate grade point the average right passing the enrollment year and the the collection of classes right and all my classes were art history and physics right and now calculating gpa for all classes in the year 2018 and it went and handed off to that other method so it's calculating gpa for 2018 including art history and physics now to continue mufon's question um would you in the same method deserialize data to json or whatever json javascript object notation format is what that acronym means um yes i i would certainly do that i would have that deserialization it's it's such a simple thing to do there are libraries that will handle that for us so it deserializing json should be one or two lines of code so not too bad to get that type back but there's times and places where you want to or you need to violate that seven lines of code rule and that's okay that's okay so absolutely i would d serialize json hand it off to whatever the processing is that you're going to do and return some sort of a value i think that's perfectly fine to do to convert that that data type however just like i did here nesting methods maybe you create another method that does that conversion from json and hands it off to the next method so yes absolutely i vote lol keep it simple without question physiotronic has our next our next question what if i want to have a method with a real optional value real optional what do you mean by real give me a little bit more context do i just set it to null or false or something like that and then in the method i detect if it's null or not in this case you don't know if 2020 comes from you or it's set by default okay that's fair so if you want to have a really optional value really really optional i'm not quite sure how really optional um but right we could set this to be um right set it to you have to give it an up a value to default to right and if we want to investigate in default enrollment year to this year i can't have this be um date time now year see that doesn't work th this what's on the right side of the equals must be a constant so if i default it to zero and nobody's gonna ask for an enrollment in the year zero right this is something i can figure out i can add a conditional here to test and say well if it's zero set it set it to the year the current year right so right we haven't and we haven't done conditionals yet um so i can say if uh enrollment year equals zero then we'll set enrollment year equals date time now year um oh and we need to convert that oh fine there we go and now right we're forcing it at that point and you can see it defaults to uh well i passed in a value there if i get rid of that it defaults to the current year from how we calculated so does that help physitronic let me know um [Music] i'm going to queue up a couple more questions here so next the next question is here from evan weeks evan evan asks can i write a reusable method to do that so that all of my ap all api calls can reuse that method oh yeah all methods can call each other build and reuse as much as possible if there's one thing about us as developers it's that we want to write as little source code as possible some folks even call that code golf right because we want to write as few lines of code as possible um and reuse as much as possible so oh yeah if you can avoid repeating code you'll do it absolutely evan go for it if th that functionality is specific to that api call might keep it in inside of that api yes reuse as much as possible right um so here where i'm calculating gpa for all classes i'm right i'm handing off and i'm doing the actual calculation over here right and maybe i just turned this into right return that right so now i've literally handed off and gone and said go actually do the calculation over in this class where it knows how to do that and i'm i'm setting the default values here so i can do that interaction excite absolutely you make friends you may see this acronym that excite is referencing here keep your code dry do not repeat yourself dry do not repeat yourself don't is they'll in english they'll concatenate that together for that contraction and yes don't repeat your code don't write the same code over and over again um comment there's a question here from phonemyatt and this is kind of solidifying i need to get into loops next is it better to use 4h or link 4h for a more functional approach to each of their own that's a design decision well and we can talk and get into those in our looping session and i i think i put loops uh nope not that one i think i put loops as the next session we're gonna do um interfaces abstract classes let's move loops up and get it and i think we need to do loops and conditionals i think we need to do these together so absolutely we will talk more about it we'll we link i think is a little bit further out but we'll definitely talk about these two um async await is gonna be a lot further out um i may even move that over to nah it's gonna be towards the end but um let's put link in here that's something that's going to be much much further out uh convert that to an issue yep and um it's probably going to be right after collections that we'll talk about link and label that as a no no no hang on future show id there we go cool all right um ivo lol asks is that firefox yes it is yep i like to use firefox on stream um we are an equal opportunity browser offender you'll see me using um microsoft edge you'll see me using google chrome you won't see me using safari because i'm on windows i mean i could do it but that's a thing um let me see here oh my gosh you're right i misspelled link wrong link that should be see i i got all i got all clicky here hang on wrong link that should be linq no just edit it right here edit that that link my bad thank you um this stands for language integrated natural query it's a sub a subset of features in c sharp that n dot net that we can use to work with collections and you know what let me just stick this right at the end after the collections show that we're going to do so because collections is a whole topic to itself all right and actually um i'm thinking we're going to want to move i'll work on the schedule later okay all right moving on in addition to passing in parameters in passing in arguments to our methods we can pass arguments out using the out and ref keywords that feels weird i'm calling a method and i'm receiving a value being passed out through an argument so if i'm going to return two things i have if i have a method called enroll and i wouldn't want to return some success indicator of boolean type true or false and i want to return hey what's your new student id because you're now enrolled in class i can use the out keyword to indicate here's your student id so i can define here's my new student i have an id that i'm going to receive my student id that i'm going to receive and the year that i'm enrolling for so i can now say student enroll for 2020 and receive out the id value and when i enroll i enrolled successfully because i returned the value true and my student id is now been populated with the value that was set inside my method now when you use an out keyword like this on a parameter you need to you need to set that value before the end of the method if you do not set a value to that it is a compiler error okay so you've been warned that this is a requirement that you do need to in fact if you provide an out variable set that variable before you return it before you complete it ah so mr smoofy you're that is a very good question that we can we can get into um and it's what's a good rule on the number of outs versus returning an object with those values instead that is a very very good question and this is another class design thing depends i don't like to have more than one out parameter on my methods if i create more than one out parameter that tells me that you're returning more things that are going on there i do like to have some sort of a status indicator that i'm returning from um api interactions right a boolean that indicates success or maybe a status code that i'm returning but for whatever interaction that i've done i'm returning a value that says well here's all the things that i created all the things that i interacted with i want to create only one out parameter when i build interactions with my methods that's me now there are other ways to do this using a technology called tuples now a topol is a way for you to group together anonymously multiple multiple types in a larger type without going through the rigamarole of creating a class and i think let me add that to the list of things to talk about when we get into are classes versus structs over here when we get into this discussion because i think not only do we need to talk about structs but i think we also uh we should also uh talk about uh tuples here those those kind of pseudo-anonymous types that allow us to pass around values that are related so um did i add innumerable i don't think i've done innumerable and actually i don't did we do enum we might not have covered enum yet comments type casting operators date types no we didn't get into enum did we we need to get into enum at some point um i'm going to move this over here um i need to figure out where this where to sneak in enum let's put enum in here um also talk about enums so enums are enumerated types so uh this is quickly becoming a catch-all and i have a feeling we're gonna end up breaking that out a little bit all right so um let's go back over to this all right now what about ref reference types we talked previously in a in a previous session about value types versus reference types value types are those basic built-in types typically like numbers or characters or even boolean types that you're passing around a string because it's made up of multiple characters is a reference type whenever you're passing those reference types around you're not actually passing that object but instead you're passing a pointer to some place in memory now for us as humans interacting and writing our code it you're passing that type but the actual code that gets compiled behind the scenes is passing a pointer to wherever that thing lives in memory so we can take our value types like our numbers in this case an integer we're going to pass into our do something method here and we can instead of passing it by value right we if we were passing that integer in it would be by value and we would interact with it and something would happen and right whatever so um so if i say um s dot uh do something right and we pass in let's pass in that year right the year is is listed as 2020 and if we display the year again right after this right i still get 2020 being returned now if we change that to a ref so we pass it by reference this says instead don't pass 2020 in but instead pass a pointer to where 2020 is in memory so now when i execute that what uh oh um oh nuts all right let's change let's define into my value um so that i'm not changing things around here so i'll do the exact same thing here but i'm going to have an integer right you make me sad you know what now i pass the value 2020 and i'm passing it by reference and now it's displaying that it incremented by one right if i take that ref off i pass the value 2020 in even though inside of here right right if i say um inside of do something um my value is right inside of do something my value is 20 21 but outside after it because it it's modifying the value inside of there it isn't actually changing the the property the um the this my value let me change that let me call this uh my let's call this my var out here just so it's clear that this is something different my var is right it's changing the inside value right it's allocated additional memory because you pass it by value into that method to interact with but outside it's still the same now okay right let me change that back one more time just so you can see that inside now because i passed it by reference it's that my value and my var are pointing to and referencing the same thing in memory and that's what it means by reference i see a couple folks trying to ask questions here and they're passing through stuff that looks like links evan weeks with a link to the list of primitives we we have that link in our first session notebook where we talk about the primitive built-in types here and you can click through and see them all that you can interact with and that's from our first session that we had back here um what's the use case of ref and out i'm can you give me a phone my att can you give me a little bit of space in in there so it doesn't look like a web address and we can answer that question um you there are cases where you want to pass things by reference here like this because you want to interact with those with those types without allocating extra memory right some of this is a performance optimization some of this is because you want to act on that type that thing that you're passing in and be able to update it from inside the method without having to go and interact additionally right maybe i have a right maybe i have a method here um right that is uh manage shopping cart [Music] right or um delete items from shopping cart right and i have uh int um number of items well i don't want to pass that right now i can say well get rid of everything in the shopping cart number of items equals zero right and i've i've wiped out i've said i i've cleared that out and i may take whatever other steps to delete those items from the shopping cart put them back in stock put them in inventory i can do those things and and yes you're right tinker tinker foo if i use ref with a value type i'm changing their value within the method now those are with the primitive data types the value types that we have like integer character the various numbers booleans if we have a more complex type something that's created from a class those are reference types and you don't have to pass them with the ref keyword they are by default interacted with by reference and i think i include that here yeah so if we add another method here right um let's add that grade class in right let's add that back in grade um right and if we put a property here oh that that doesn't work um public string that uh decimal um [Music] final score i don't know right so we have this um and write public void uh calculate grade right and uh if we're receiving a great let's also put a class on uh write a string uh name of class right so now when we interact with this maybe i should do this right so there's the i can separate this out so that it's in the the lower section here where i talk about reference types now you know what here's what i'm gonna do i'm gonna copy that let's i'm gonna click in here go right here split that and paste it right there now i can get rid of some of this other nonsense um right because this sample up top is getting a little bit more complex so now down here i have enroll i have do something let me get rid of this and that one let's also get rid of this um grade as a reference type is always passed by reference okay so um here i can say um a grade let's just call it g i can say g dot uh final score equals 0.9 make it a decimal so now if i have a if i have a new student and if i say var g equals new student grade right and i will call name of class um write physics and if i start with final score equals and let's say the final score oh we're not doing too well we're laying at 70 percent right i can say display g okay and now let's um calculate grade pass in the g and display g again now you see it passed it by reference i created my my grade my complex my reference type with these two properties physics and 0.7 inside of the method i i set the final score to 0.9 and i'm still inspecting that grade object here and outputting the value and you see it upgraded the score to 0.9 it's the same object it's pointing to the same place in memory and we're able to see that value change okay um yes nothing else matters you're right complex mathematical function are a very good reason why you may want to do this if you're doing a lot of work pushing numbers around it's going to be very important to know whether you're passing things by ref you're passing values out different ways that you interact with those numbers and as you build out your formulas your algorithms that you're interacting with those various numeric values beyond just simple math here you're going to find being able to interact with and manage that those values in memory not just important but valuable for performance so that you're not allocating more memory for additional values that aren't really needed um phone my att makes a very good point here you need to be careful with how you use out in reference types because it can introduce bugs if you're not careful can happen so be careful with how you use these and know what the implications are when you when you drop in that ref um keyword so good pointer there phone my att thank you for sharing um evan weeks has a question here what happens when you assign a new instance of a class to a parameter inside of a method like that does it replace does it alter the variable outside of the method or replace the reference within the method let's try it let's see what happens so if we say instead here right i'm just going to comment that out if we say g equals new grade right and let's say name of class equals um let's see we did physics let's write we'll say it's it's calculus and we'll also say um final score equals and you know what i'm i'm not a very good calculus student i only got a 75 in calculus you know what i'm saying um so now if we do that interaction but what happened okay we've tried to replace that grade with a new grade here and it doesn't set that type you can't overwrite it you're trying to overwrite it it's allocated some new space in in memory and it is not by reference interacting so whatever value is whatever object is passed into your methods don't change them don't don't changes the wrong word don't replace them don't reset them because it doesn't actually do anything there okay when you're dealing with those reference types but that does work to manipulate the objects that are inside of it yep there you go evan you get a new reference to the object that's right and it does not change the outside object so absolutely so those are some of the things that you should know about how you interact with things by value by reference now now that we know what a method is now let's get into something that's a little bit more complex and this this is going to take some explaining delegates so reference types and value types define variables right and they're right a value type is a value that you pass around and a reference type is a pointer to where that type is in memory what if we could create a pointer to a method that's what a delegate is it's a way for us to create a pointer to a method we call it a delegate and we can pass that object around as that as a reference to that method so we can call it when we would like at some later time and you're gonna go do this thing later don't don't execute it now but you figure out when you want to use it later so our delegates have a signature after the keyword delegate right you're going to provide an access modifier up front the key word delegate and then you provide you provide a type a name for that delegate and your collection of arguments everything from here over not necessarily the names but the types need to match whatever method you want to assign okay so down here in the rest of this class i have a calculate method that takes in two arguments and a handler well exactly what type of calculation do you want to do well i'm going to execute that handler because i'm past a pointer to that method i can use the parentheses and actually execute that method okay that's cool but then i'm interacting and returning right return the output value it's going to hand off to whatever method was actually passed in there neat i have these two methods that match that signature it's an integer that it returns and it passes in two integer arguments and does some code i don't care what the code is now you instantiate a delegate using a new keyword and you point at whatever that method is you want it to execute add maybe right and i can say calculate i'm passing in my two arguments to calculate 10 and five and the calculate handler i chose was add so it's gonna pass that in so this add method is passed in as a pointer here on calculate handler and this is actually a pointer it's by reference back to the add method so when i execute here calculate it returns and goes through this method and displays the work the phrase added and my output and returns the output so i can change this have this method do the exact same things and i can point it to subtract and it'll do the subtract method instead so i'm passing around references to methods and like i said it's important that the signature matches right if if i had changed this and this is a a short well that doesn't match the handler it's you you can't do this because it's not the same okay they need to match signature i exactly the same that's right five commando that that's a very good point i can i should use that reference here is this the same as a callback function precisely that's another term that folks use for delegates um let me add that in thank you so much for reminding about that um delegates are sometimes referred to as um callback functions because yeah it right we're passing in and saying hey call this later go ahead we're gonna do this thing later now there's the callback functions there's a couple different ways that you can structure these and we'll see a little bit here because we can also provide anonymous methods so if we take that same student that we have up here and if we say calculate handler right we create a new calculate handler and this time we're going to create a handler called multiply right so here's our delegate called multiply and now we provide this um expression-bodied member so our expression body member takes in arguments right it's a so we have our arguments in the same signature int int the names of the arguments don't have to be the same right i can i can call these right not foot foot foo and bar and i can make this foo and i can make this bar and i pass now multiply in and it multiplies so this is how right we can we can now extend and have this this main method do additional things right because i'm passing in other things that i want to do there that aren't necessarily inside of the class so those are ways that we can pass around different types and the same thing that that we saw earlier about the signature must match right that doesn't work and it refers to it as a lambda expression here right um if i just do that see it doesn't it doesn't match so um [Music] right go back there we go and it works so that's right something that that you need to um you need to know is making sure that that signature matches the reverend three how you doing there the reverend let me bring up your question if i don't specify the data types would it automatically infer the type let's give it a try so i'm going to delete the data types there right so it's foo and bar and yes it does it infers the types because i've specified that it is a calculate handler it knows what those types are these are the names of the variables that i'm going to receive and go forward at that point right this is these are ways for you to shortcut and make your code even more terse make it as as short and simple as possible for for us as humans to read now some folks want that to be a little bit more explicit they want they want to be able to specify the exact types so that as you go through and read it's a little bit clearer and that's just a preference choose and write the code the way that makes you happiest makes sense all right glad to hear at the reverend uh how's it going there bizmonger yes there's there's definitely some space for some f sharp learning that could be done but we're covering c sharp here so now we passed in one method and as a delegate well what if we want to pass in a stack of delegates go execute all of these things for that delegate so we can create what's called a multicast delegate so when we define a type right a delegate type and we pass in multiple implementations we concatenate them together it will then go and execute all of those so check this out var calculation we're going to define an initial delegate variable using that same student class that we had earlier student calculate handler add and we're going to attach the subtract handler as well when i execute calculate this time passing that in it executes both of them now it doesn't pass from one to the next they don't chain together but they each execute individually and they execute in the order that they were attached right if i if i change if i change this around hey hey um if i change this around i put subtract first right it runs subtract first now i'm concatenating them using the plus there but sometimes you don't know what it is right well and we saw how to do plus equals in a previous stream well if i do plus equals uh calculate what do you mean it doesn't exist in the current context that's right oh calculation it does the same thing we're now putting together our list of here's the various handlers we want to concatenate together we want to execute these all at once and just like i'm showing here in the commented out section i can even add in multiplied with that same signature that we saw earlier right i'll even get rid of the types here arc 2 and now it runs all three of them i can remove operators to right i can get rid of these right so i can come down here and i can say calculation uh minus equals and let's get this subtract one out of there right if i bring that down here now it doesn't subtract when i execute so you can attach and remove delegates right these methods that we want to execute from the delegate variable type with using plus and equals um delegates used to have a deadlock problem um okay so now that you know how these pointers to methods work now we can talk about events so events are ways that you can notify other places other classes other elements in your program when something has happened inside of your class so we're going to take the concept of a delegate that references another method and we're going to use that with an event so that the event has an event handler delegate by by not definition but by convention it has an event handler type of delegate that is the pointer the event will actually go and execute when the event occurs so if and and by default the event handler by convention has this syntax of whatever object is sending as the first parameter the second parameter is a collection of arguments wrapped up as a class that descends from the offen event arguments type so this is a little bit about inheritance where we're inheriting from this so that it knows it's an event argument so i've defined my delegate that says we're going to handle the event enrolled we're going to specify some method that's going to handle when you've been enrolled as a student and we have an event that is specifying i'm going to trigger a method that looks like this syntax and i'm going to call the event that will trigger that method enrolled it has an access modifier in front of it public can also be private can also be internal protected all of those access modifiers so i've created a method inside this class called enroll now maybe it's going to go and do something maybe do some maybe do some long long running process on another service um another machine somewhere else when it's done i'm gonna notify you're done we've enrolled you so i return i i trigger and notify this event completed by calling the enrolled method as though the enrolled event as though it were a method with that same signature that we defined for our delegate enrolled this right i'm passing a pointer back this is the object that triggered it um and new event rolled arguments and here's the year you've been enrolled consequently i can wire up that event using it's a delegate using the plus equals syntax to attach and in this case i'm using an anonymous method i'm using an expression body member that's receiving that's passing that's receiving a sender and arguments and i'm just going to call display hey i'm now enrolled for the year and the year that i was enrolled when that event was triggered so now if i call that method it the event is raised and this is returned so this is a way for you to go and perform a whole bunch of different tasks that go do whatever code interactions that you need and when something happens that somewhere else they need to be notified hey this thing occurred we can have that event raised and in that other class in that other place in our code handle it go do something appropriate for that ah that's right emmanuel i am on the visual studio channel today and we're hosting over on the uh on the c-sharp fritz channel and we're also being featured over on learn tv today all right so that's where i stopped but i think there's more that we need to talk about with events and let's talk about this is kind of annoying having to create a delegate like this right i if i have to create one of those for every type of event it's going to be really annoying and cumbersome and it's a lot of extra code that just floats around and no and if we're always using the same type of signature object sender and some event arguments here wouldn't it be great if there was a simpler way to define this so here's what you can do let me create another block here and i'm going to define a new student but i'm going to say save those same enrolled event args so let's copy in our student and instead of having that event handler we're going to simplify a little bit here instead of having enrolled event handler because now that doesn't exist we can define and use what's called a generic event handler that has these angle brackets to specify the argument type that we're going to serve and in this case it is the enrolled event args so this is the exact same thing that we had above right the exact same code that we have down here the difference is instead of having to define this delegate every time we're using this very generic event handler with a the specific argument type that we're going to be receiving and now it works the exact same way so right let me make sure i include um right this is the generic event handler definition and i'll put some code some description of what that is there okay so is a way for us to interact and and right make the um the construction of our events adhere to what we consider good.net standards without having to write a whole lot of extra code you know i see a couple questions coming in in the chat room let me queue these up from phonemyatt asks can we call a list of delegates so a list of delegates i'm not sure what you mean by that if you have a collection of those and you want to go through each element in the collection and execute each one of those individually sure you can do that absolutely right and that's that's backing up to up here right if um right if i have uh my calculate handler here right if i wanted to [Music] let's see if i wanted to add some more to this let me copy down if i copy down student i'm gonna modify it before oh no no we're good all right let me copy that down so if i let me copy this and right um let's paste in another one here um this is different from executing a collection of delegates as seen below okay so if i have my calculate handler if i wanted to pass in here we go uh params calculate handler and i'm specifying this as a collection this is an array of those handlers well right now i can't just do handler arc one arc two um i need to iterate over each one and do something with it right so um right not just calculate handler s subtract um right i can also say calc handler plus equals uh s add well now what's right now i um um no wait wait wait wait wait wait right take this and say s subtract s add and where are we at here line seven where am i running so now this is a collection that it's running into right um i'm gonna want to do something with those so i might change this to say display and and um i don't know force that to zero and uh do this as a four each right uh h in let's call this handlers right and we'll call that handler so i'm gonna get one at a time there uh for each oh there we go so now it's executed each one of them because i passed in a list of those and you can decide how you want to chain them together if you'd like but it's now executing them in order that we've we've passed them in um evan weeks using a non-void return type delegate within uh no you're supposed to return an event handler with an event yeah this is the way they they want you to interact with this right and um where was the delegate that we used um you're right that should re what does the event handler this return i forget return something but you're right that shouldn't be a void i forget what it's supposed to be um right if i go up here where's the events doc here this one right so that delegate yeah public delegate void event handler yeah public delegate void custom event handler yeah yeah we're good and you have a public event of type the ad event handler yeah we're good with that so um event handlers there's another question here from evan let me bring that up is it possible to use a non-void return type delegate as the type for an event and then process the subscriber list with get invocation list ah so you can from right you can go through that um not just pass in um then gosh it's been a while since i've done this um right so i passed in a list of those here like this right if i take this and turn it into handlers in handlers get invocation list right i think that works um so now instead of that i can do this um oh wait wait wait no no no no um let's see uh calc handlers equals uh s add s subtract right and now i can pad right i should be able to pass it i did that earlier count handlers no why don't you like that new student dot uh calculate handler wait a sec student calculate handler what am i missing here what am i missing here friends um because i did it just fine up here let's wrap it to start [Music] right if we say new like that ah there we go target typed object creation is in preview no we're not doing that um so you can get the invocation list and it'll return the collection of those this isn't gonna work for me here but you can with the multicast delegates reach in and see all of the things that have been attached um but it's not going to work for me right here so i'm gonna roll that back to where i was passing in a list of those which isn't terribly uh useful right that's kind of weird um i forgot the params keyword not terribly useful but when you have those multicast you can reach in and interact with them yes the the notebooks are available on github there's the url for you [Music] all right um i can't change the docker compose file that's there because i need that in order to deploy to um [Music] in order to deploy to binder so there's um we would need to put a different docker file somewhere if you want to put that in another folder like deploy local or something or dist we can do that if you want to submit a pull request i i want to update the docker file that's in there anyway because right now it builds all the net interactive stuff and i don't want to build that every time i want to put that into a base image that we build on top of oh you're adding a docker compose i think you can do that sometimes you think.net is too powerful to do all sorts of things um with with great power comes great responsibility right that's a thing um let me so the last thing that i wanted to show you today was the partial keyword um and i wasn't sure if i was going to get to it and that's why i didn't include it in the initial the initial definition of what was in the notebook um so let me put it to do here um and i'll i'll put some docs in there but the partial keyword lets us define classes and methods with only part of a signature and you can put them then in separate files when dotnet compiles it'll it'll bring those together it'll coalesce it'll it'll board them together right and like like the the ships you saw in star trek right it's going to take them and slam them together so they're one object that you interact with so let's create a public partial class and let's let's make this something different from student let's make this um uh let's make this a teacher right so we have a public partial class teacher and maybe in this part we have a public string for name right and down here we can say um var t equals new teacher right uh name equals frets right and display t right and there's you can create another class write another class file that includes that references that same class name and it won't ding you for recreating it right um public date time birth date right and see now it's getting a little confused because it it thinks there i'm redefining it here this is a jupiter notebook thing if you define these in separate files it would actually bring them together i'm gonna have to create them in the same block so let me um let me merge these two cells this one and that uh how do i how do i merge the two nope it's not merging how do i merge it how do i select multiple cells let's try there so um select cell above select cell below so let's go okay no not there over here okay now see i want to select multiple cells i'm trying to hold down shift and wow that worked all right and if i do shift m ah there we go so now i have two of these and write two separate class definitions and it merges them together to create one teacher object so right now i can refer to and i can say birth date equals new date time um 2000 august 28th and there we go so it merged those two objects together right and i can also provide method signatures inside of one an implement in another that's right uh nev nevsner nevsner g i always have a problem pronouncing that name um this you can only merge classes like this in the same library in the same dll that that's important because right you don't want folks to be able to kind of add features into your class and access the internals of your class from somewhere else right um so if i if i turn this around and i made this um right if i had this actually save inside of a birth date field right right so birth date equals value value um right and i have over here uh private date time birth date right that still works and if i add into up here right if we add a add a method right uh int get age right i can say return and you might have made this a property but no matter datetime.now subtract um birthdate dot i can't do years right i can't do total years uh but i can do total days divided by 365 right uh oh i forgot to send me calling um can i convert double to an int yeah i know i know right and if i say t dot get age now there we go so it reaches across the types right that not types the partial classes to do that interaction and these are a way for us to reach across you see this in entity framework you see this in some of the user interface framework where they define all the display considerations in one file you might see right myform.designer.cs and it has all of the information about what you put in the user interface and you'll have myform.cs that is another partial class that contains your business logic and how the code that you wrote to interact with the user interface on click events for instance is uh one place where you'll see this actions and and funks um i was going to get into those with link so yeah um let me add those with with link down here make sure i add action actions and funk make sure we get to that topic over there okay now you can also provide this is where it gets a little weird you can provide a signature for this method make sure i'm doing this right i think i'm doing this right and over here you can actually provide the implementation uh partial methods must have void ah [Music] nuts that's fine so we can do this right instead of that we can say display uh i need to cast it to int still partial method can i have yeah yeah yeah um virtual abstract override new sealed i did can i convert from void to object what am i missing here can i have access modifiers uh okay fine yeah yeah yeah see that now i can't get to it um but i could add um public void um display age and chain these together right [Music] now down here this becomes can i convert from void what what let's see now this isn't clear to me where this is that's annoying partial void ain't from void to object i'm not quite sure where it's running into calling display inside of display ah you're right display h doesn't return so now it calls display h there right thank you right so i've defined a signature of hey somewhere else you need to fill out what this method does and i've added it down here behind this method right so that's one way that you can right in and you'll see folks do this there was a comment about entity framework earlier you'll see this where they might generate the first class and they they leave these methods here as a as a signature so that you can fill in and complete that method in another part of the class down here and you see this with entity framework they do this sometimes um they also do this uh they they used to do this with um with asp.net web forms you'll see this type of approach not typically used folks like to use a little bit more hierarchical approach to handle um filling out and completing methods in with today's uh syntax that folks use um looks suspiciously like c plus plus header and c plus pl and cpp files it can yes right but like i said folks will use this as right here's code that was generated here's your code that you wrote that way we can regenerate the the top um class several times keep regenerating it and it doesn't blow away it doesn't erase the code that you wrote it does massive quasar abstract methods and classes are something we're going to get into i believe i have that set up for two weeks out we're going to talk about that abstract methods and classes and getting into a little bit of a little bit more object-oriented programming and how we can interact with that code all right chat room what do you think um so i'm gonna i'm going to go through um well i'm gonna save what i have here for our notebook today um that's all i wanted to cover around you know what i can do enums right now um hey good morning dev nelson um massive quasar would like to know the the difference between doing partials like this abstract uh classes and interfaces when you define a partial like this right partial classes like this these are separate files that that get mashed together and it's the same concrete type teacher abstract classes and interfaces are ways for you to define an entire hierarchy not just teacher but school staff and school staff could be other folks like like uh the custodial staff the cafeteria staff the the administrative staff um so and and all of those are people and people have names and ages so you have that hierarchy of objects that goes across all of the various types that you might define in in your library in your application in this case this is a type that is being defined in two separate locations and that one type teacher is being merged together so that you only have one teacher type with all of those features they're teacher features that's a thing i just i just made that a thing teacher features i i don't okay how we doing there got it all right um you know what i've got just i've got seven minutes left what do you say i sneak in one more topic i can sneak in one more topic i think i can i think i can i think i can let's talk about enumerations so an enumeration is a way for you to specify a type that has multiple values think about that for a second not just true and false but other values right so you define an enumeration with the enum keyword and the name of the enumeration you put an access modifier in front but you then specify well what's the name of this so maybe i have a light switch and it's it you then have a block and my light switch has two values um off and on and i specify those are my two values so then i can specify right well i'm going to have a light switch and um i'll call this the one in the hall and i will specify its value is uh light switch off because everybody turned off the light switch in the hall know what i'm saying and um yes i need to put a display in front of it and it tells me that it's off now maybe your light switch has a dimmer effect on it and you don't just have off and on but you have right you have um off uh maybe you have uh 50 percent right um um bright uh nuclear and on right so i can turn it off but i can also set it to bright and i've got these different values now that i can pass around for how my light switch is defined and you can use the enum type light switch as input parameters as output parameters anywhere that you would use a variable type inside your classes inside your code the enum can be defined inside of a class or outside of a class and you can reference it then throughout all of your code so you'll you'll typically see folks they'll create um enums let me let me put this in a new um so if i do that let me create another block here so um right if i have my student again right student and maybe i have an a enum and that is the uh enrolled state right so it's not just you're not enrolled or you're enrolled but maybe you're maybe you're off on a mentorship right um on uh mentorship right or um right you're you're on an internship right or maybe you're on military leave right so now when i set up my public in my enroll method right i can return an appropriate enrolled state there right uh enrolled state dot enrolled i have to reference when i return and eat and i interact with the enum values the type of the enum enrolled state and the value of it right so var s equals new student s dot enroll okay and let's display that and i'm enrolled maybe you know right maybe right evaluate you know uh whatever the student's scenario uh make a decision and this time uh you know what they're on military leave right so those values are being passed around and we can decide appropriately i want to wrap up here i've got two minutes left before before we end um another cool thing you can do with in enums is you can also make them flags so that you have one enum that has multiple values so um you decorate them with the flags attribute so um maybe this is a series of status codes right or oh read write access in um in unix right i have file access right and it's uh read write execute in in unix now by default these values are 0 1 2 right but you can specify you can override values by using equals like this and now i can say var access equals file access dot read right and let's display that and it's read but i can also grant that ah it's not a plus my bad it should be a vertical pipe which is a logical or and i can also attach execute and now it's concatenated these together so you have one value one variable but it's got all three values of the enum i will be sure to add some content there and i will update this appropriately we are right at time thank you so much friends for tuning in i'm gonna update this and get the video out on youtube it'll be out there later today but um we've gone through and covered a lot today um my goodness let's um let me pause the music and we can wrap up i know we've just lost our friends over on learn tv thank you so much for joining us this video like the other videos in this series we'll be over on the youtube channel youtube.com.net look for the fritz and friends playlist and you'll see it out there later today with links to your questions links to the github repository and with an updated version of this notebook with all the notes that go on in there with all the details of the things that we've added in and we've learned along the way thank you so much for joining me i look forward to seeing you next week right back here and for our next topic on c sharp with c sharp frets take care
Info
Channel: dotNET
Views: 7,386
Rating: undefined out of 5
Keywords: .NET, c#, csharpfritz, csharp
Id: -E2xB4kOSV0
Channel Id: undefined
Length: 116min 54sec (7014 seconds)
Published: Tue Aug 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.