title
C# Methods Tutorial | Mosh

description
C# Methods Tutorial 🔥Get the COMPLETE Course: http://bit.ly/2LhL39u SUBSCRIBE FOR MORE VIDEOS! https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1 STAY IN TOUCH https://www.facebook.com/programmingwithmosh/ https://twitter.com/moshhamedani

detail
{'title': 'C# Methods Tutorial | Mosh', 'heatmap': [{'end': 223.657, 'start': 201.331, 'weight': 0.702}, {'end': 300.692, 'start': 234.64, 'weight': 0.828}, {'end': 384.927, 'start': 367.268, 'weight': 0.793}, {'end': 582.852, 'start': 557.473, 'weight': 0.875}, {'end': 646.392, 'start': 617.698, 'weight': 1}, {'end': 882.004, 'start': 868.19, 'weight': 0.716}, {'end': 1216.706, 'start': 1171.274, 'weight': 0.799}], 'summary': 'Tutorial on c# methods by mosh covers advanced methods, method overloading, and modifiers like params, ref, and out. it emphasizes best practices to prevent null object exceptions, defensive programming, and global exception handling, while demonstrating the creation of a calculator class with various method implementations.', 'chapters': [{'end': 79.735, 'segs': [{'end': 79.735, 'src': 'embed', 'start': 21.998, 'weight': 0, 'content': [{'end': 25.521, 'text': 'because I already talked about in the lecture about constructors.', 'start': 21.998, 'duration': 3.523}, {'end': 29.904, 'text': "But here you're going to see another example of overloading methods, which can be useful.", 'start': 26.121, 'duration': 3.783}, {'end': 38.493, 'text': "Then I'm going to talk about three modifiers that we can apply to method parameters, and they are params, ref, and out.", 'start': 30.825, 'duration': 7.668}, {'end': 43.358, 'text': 'Out of these three modifiers, params is the only one that I consider useful.', 'start': 39.554, 'duration': 3.804}, {'end': 49.444, 'text': 'In my opinion, ref and out are bad decisions made when designing the C-sharp language.', 'start': 44.439, 'duration': 5.005}, {'end': 53.187, 'text': "They're code smells, and a lot of developers have the same opinion.", 'start': 49.904, 'duration': 3.283}, {'end': 57.809, 'text': "Initially, I didn't want to include them in this course because I don't want to teach you bad things.", 'start': 53.988, 'duration': 3.821}, {'end': 62.45, 'text': 'But because I wanted my course to be comprehensive, I decided to include them here.', 'start': 58.409, 'duration': 4.041}, {'end': 67.712, 'text': 'Plus, there are areas in the .NET framework where you have to use the out modifier.', 'start': 63.391, 'duration': 4.321}, {'end': 75.474, 'text': "So I want you to know how to use them, even though I'm not going to advise you to use out modifier when designing your classes and methods.", 'start': 68.612, 'duration': 6.862}, {'end': 78.095, 'text': "We'll see the reasons later in this lecture.", 'start': 76.274, 'duration': 1.821}, {'end': 79.735, 'text': "So let's get started.", 'start': 78.915, 'duration': 0.82}], 'summary': 'Example of method overloading demonstrated. params, ref, and out modifiers discussed, with emphasis on params. ref and out considered bad design decisions. included in course for comprehensive coverage, but not recommended for use in designing classes and methods.', 'duration': 57.737, 'max_score': 21.998, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU21998.jpg'}], 'start': 3.522, 'title': 'C# methods and modifiers', 'summary': 'Delves into advanced methods in c#, covering method signature, method overloading, and modifiers like params, ref, and out, highlighting the usefulness of params and critiquing ref and out as bad design decisions.', 'chapters': [{'end': 79.735, 'start': 3.522, 'title': 'C# methods and modifiers', 'summary': 'Delves into advanced methods in c#, covering method signature, method overloading, and modifiers like params, ref, and out, with an emphasis on params being the only useful modifier and a critique of ref and out as bad design decisions in c#.', 'duration': 76.213, 'highlights': ['The chapter covers method signature, method overloading, and three modifiers: params, ref, and out, with a focus on params as the only useful modifier.', 'The instructor criticizes ref and out as bad decisions in C# and expresses reluctance in teaching them but includes them for comprehensive learning, emphasizing that they are considered code smells by many developers.', 'The instructor acknowledges the necessity of teaching the usage of ref and out due to certain areas in the .NET framework, despite not recommending them for designing classes and methods.']}], 'duration': 76.213, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU3522.jpg', 'highlights': ['The chapter covers method signature, method overloading, and three modifiers: params, ref, and out, with a focus on params as the only useful modifier.', 'The instructor criticizes ref and out as bad decisions in C# and expresses reluctance in teaching them but includes them for comprehensive learning, emphasizing that they are considered code smells by many developers.', 'The instructor acknowledges the necessity of teaching the usage of ref and out due to certain areas in the .NET framework, despite not recommending them for designing classes and methods.']}, {'end': 409.042, 'segs': [{'end': 124.476, 'src': 'embed', 'start': 81.001, 'weight': 1, 'content': [{'end': 88.364, 'text': 'What is the signature of a method? The signature of a method consists of its name and the number and type of its parameters.', 'start': 81.001, 'duration': 7.363}, {'end': 92.505, 'text': 'So in this example, you see we have a point class that has a method called move.', 'start': 89.084, 'duration': 3.421}, {'end': 98.087, 'text': 'I have highlighted the areas where I make up the signature of this move method with yellow.', 'start': 93.345, 'duration': 4.742}, {'end': 101.788, 'text': 'So the name and the type and number of parameters.', 'start': 98.807, 'duration': 2.981}, {'end': 107.07, 'text': 'A concept that goes hand in hand with the signature of a method is overloading.', 'start': 102.849, 'duration': 4.221}, {'end': 113.414, 'text': 'So basically overloading means having a method with the same name, but different signatures.', 'start': 108.513, 'duration': 4.901}, {'end': 115.831, 'text': 'Look at this example here.', 'start': 114.71, 'duration': 1.121}, {'end': 118.472, 'text': 'We have a point class with three move methods.', 'start': 116.311, 'duration': 2.161}, {'end': 121.374, 'text': 'Imagine this point represents a point on the screen.', 'start': 118.853, 'duration': 2.521}, {'end': 124.476, 'text': 'And we would like to move this to a different location.', 'start': 122.355, 'duration': 2.121}], 'summary': 'Method signature includes name, number, and type of parameters. overloading allows methods with the same name but different signatures.', 'duration': 43.475, 'max_score': 81.001, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU81001.jpg'}, {'end': 200.591, 'src': 'embed', 'start': 172.607, 'weight': 0, 'content': [{'end': 178.971, 'text': 'you can improve your code and make it easier for the consumer of your method, overloading is a technique in your toolbox.', 'start': 172.607, 'duration': 6.364}, {'end': 185.414, 'text': 'Okay Now that you understand the concept of method overloading, take a look at this calculator class here.', 'start': 180.832, 'duration': 4.582}, {'end': 189.317, 'text': 'This class has at least three overloads for the add method.', 'start': 186.215, 'duration': 3.102}, {'end': 191.478, 'text': 'The first one takes two parameters.', 'start': 189.977, 'duration': 1.501}, {'end': 195.42, 'text': 'The second one takes three parameters and the third one takes four.', 'start': 191.978, 'duration': 3.442}, {'end': 200.591, 'text': 'But as you see, this is not an efficient way to overload the add method.', 'start': 196.67, 'duration': 3.921}], 'summary': 'Method overloading makes code easier for consumers. the calculator class has at least three overloads for the add method.', 'duration': 27.984, 'max_score': 172.607, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU172607.jpg'}, {'end': 229.055, 'src': 'heatmap', 'start': 201.331, 'weight': 0.702, 'content': [{'end': 205.992, 'text': 'What if you wanted to add 10 numbers together? Then we would have to overload the add method 10 times.', 'start': 201.331, 'duration': 4.661}, {'end': 207.793, 'text': "And that's a code smell.", 'start': 206.893, 'duration': 0.9}, {'end': 210.974, 'text': 'Is there a better way to achieve this? Of course there is.', 'start': 208.573, 'duration': 2.401}, {'end': 214.855, 'text': 'The first step to make this code better is to use an array.', 'start': 212.434, 'duration': 2.421}, {'end': 223.657, 'text': 'So instead of overloading the add method 10 times, we can declare it only once and have it receive a parameter of type integer array.', 'start': 215.655, 'duration': 8.002}, {'end': 229.055, 'text': 'With this declaration, we can use the add method like the example you see here.', 'start': 225.472, 'duration': 3.583}], 'summary': 'Avoid code smell by using an integer array for adding 10 numbers, improving code reusability.', 'duration': 27.724, 'max_score': 201.331, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU201331.jpg'}, {'end': 300.692, 'src': 'heatmap', 'start': 234.64, 'weight': 0.828, 'content': [{'end': 241.767, 'text': 'And the problem is every time we want to pass a number of arguments to this add method, we have to create and initialize an array.', 'start': 234.64, 'duration': 7.127}, {'end': 245.23, 'text': 'So we have to use the new operator and the int array notation.', 'start': 242.327, 'duration': 2.903}, {'end': 248.733, 'text': "It's not a big deal, but there is a simpler way to do that.", 'start': 246.331, 'duration': 2.402}, {'end': 251.496, 'text': "And that's when we use the params modifier.", 'start': 249.274, 'duration': 2.222}, {'end': 260.511, 'text': 'So we can change the declaration of our add method to include the params keyboard here, just before the integer array.', 'start': 254.266, 'duration': 6.245}, {'end': 263.753, 'text': 'With that, we can call this method in a couple of ways.', 'start': 261.531, 'duration': 2.222}, {'end': 272.019, 'text': 'We can use it in the traditional form, so we pass an integer array, or we can simply pass a varying number of arguments here.', 'start': 264.293, 'duration': 7.726}, {'end': 275.041, 'text': "We don't need to create and initialize an array.", 'start': 273, 'duration': 2.041}, {'end': 276.602, 'text': "And that's simpler.", 'start': 275.902, 'duration': 0.7}, {'end': 285.251, 'text': 'Again, this is not something that you use all the time, but if you have situations where your method might need a varying number of parameters,', 'start': 277.703, 'duration': 7.548}, {'end': 290.236, 'text': 'you can use the params modifier to make it easier for the consumer of that method to call that method.', 'start': 285.251, 'duration': 4.985}, {'end': 293.667, 'text': "Okay, now let's take a look at the ref modifier.", 'start': 291.866, 'duration': 1.801}, {'end': 300.692, 'text': "This is probably the only example in this course where I'm going to use names like my class and my method,", 'start': 294.648, 'duration': 6.044}], 'summary': "Using the 'params' modifier allows passing varying number of arguments to a method without needing to initialize an array.", 'duration': 66.052, 'max_score': 234.64, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU234640.jpg'}, {'end': 293.667, 'src': 'embed', 'start': 254.266, 'weight': 3, 'content': [{'end': 260.511, 'text': 'So we can change the declaration of our add method to include the params keyboard here, just before the integer array.', 'start': 254.266, 'duration': 6.245}, {'end': 263.753, 'text': 'With that, we can call this method in a couple of ways.', 'start': 261.531, 'duration': 2.222}, {'end': 272.019, 'text': 'We can use it in the traditional form, so we pass an integer array, or we can simply pass a varying number of arguments here.', 'start': 264.293, 'duration': 7.726}, {'end': 275.041, 'text': "We don't need to create and initialize an array.", 'start': 273, 'duration': 2.041}, {'end': 276.602, 'text': "And that's simpler.", 'start': 275.902, 'duration': 0.7}, {'end': 285.251, 'text': 'Again, this is not something that you use all the time, but if you have situations where your method might need a varying number of parameters,', 'start': 277.703, 'duration': 7.548}, {'end': 290.236, 'text': 'you can use the params modifier to make it easier for the consumer of that method to call that method.', 'start': 285.251, 'duration': 4.985}, {'end': 293.667, 'text': "Okay, now let's take a look at the ref modifier.", 'start': 291.866, 'duration': 1.801}], 'summary': "Using 'params' modifier facilitates calling methods with varying parameters.", 'duration': 39.401, 'max_score': 254.266, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU254266.jpg'}, {'end': 396.25, 'src': 'heatmap', 'start': 367.268, 'weight': 0.793, 'content': [{'end': 369.55, 'text': 'It will not affect the original A that we had here.', 'start': 367.268, 'duration': 2.282}, {'end': 376.245, 'text': 'We can change this code by including a ref modifier to our method.', 'start': 371.704, 'duration': 4.541}, {'end': 384.927, 'text': 'And note that here I changed the name of the class and its method from my class and my method to weirdo and do a weird thing because it just is weird.', 'start': 376.605, 'duration': 8.322}, {'end': 390.909, 'text': 'So, with this change, if we call this method and also include the ref modifier here,', 'start': 385.787, 'duration': 5.122}, {'end': 396.25, 'text': 'the original a that we have here will be passed to this method and its value will be modified.', 'start': 390.909, 'duration': 5.341}], 'summary': 'Adding a ref modifier in the method changes the original a value.', 'duration': 28.982, 'max_score': 367.268, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU367268.jpg'}], 'start': 81.001, 'title': 'Method overloading', 'summary': 'Explains method signature, overloading, and the use of modifiers to simplify parameter passing, with examples provided. it also emphasizes the limited practical use of the ref modifier.', 'chapters': [{'end': 172.607, 'start': 81.001, 'title': 'Method signature and overloading', 'summary': 'Explains the concept of method signature, which includes the name and the number and type of parameters, and its relation to overloading, where methods with the same name but different signatures are used to simplify the usage of a class, with examples provided.', 'duration': 91.606, 'highlights': ['The concept of method signature is defined as the name and the number and type of parameters, with examples given of a point class with a move method showcasing its signature.', 'The concept of overloading, involving methods with the same name but different signatures, is explained with examples of a point class having multiple move methods, including overloads for different parameter types.', 'The benefits of overloading are highlighted, such as simplifying the usage of a class by providing different method signatures, making it easier for consumers to choose the right overload based on the parameters they have, with examples of overloads for different parameter types and a third overload for creating animations.']}, {'end': 409.042, 'start': 172.607, 'title': 'Method overloading and modifiers', 'summary': 'Discusses method overloading and the use of params modifier to simplify passing varying number of arguments, and explains the use of ref modifier to modify the original value of a parameter, emphasizing its limited practical use.', 'duration': 236.435, 'highlights': ['The chapter discusses the use of params modifier to simplify passing varying number of arguments to a method, avoiding the need to create and initialize arrays for different number of parameters. Using the params modifier, the add method can be declared to receive a parameter of type integer array, allowing it to be called with either an integer array or a varying number of arguments, simplifying the process and avoiding overloading the method multiple times.', 'The chapter explains the limited practical use of the ref modifier, emphasizing that it results in a code smell and should be avoided, as it modifies the original value of a parameter, which can lead to unexpected behavior. The use of the ref modifier to modify the original value of a parameter is illustrated, highlighting that it can lead to unexpected behavior and should be avoided due to being a code smell.']}], 'duration': 328.041, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU81001.jpg', 'highlights': ['The benefits of overloading are highlighted, such as simplifying the usage of a class by providing different method signatures, making it easier for consumers to choose the right overload based on the parameters they have, with examples of overloads for different parameter types and a third overload for creating animations.', 'The concept of overloading, involving methods with the same name but different signatures, is explained with examples of a point class having multiple move methods, including overloads for different parameter types.', 'The concept of method signature is defined as the name and the number and type of parameters, with examples given of a point class with a move method showcasing its signature.', 'The chapter discusses the use of params modifier to simplify passing varying number of arguments to a method, avoiding the need to create and initialize arrays for different number of parameters.', 'Using the params modifier, the add method can be declared to receive a parameter of type integer array, allowing it to be called with either an integer array or a varying number of arguments, simplifying the process and avoiding overloading the method multiple times.', 'The chapter explains the limited practical use of the ref modifier, emphasizing that it results in a code smell and should be avoided, as it modifies the original value of a parameter, which can lead to unexpected behavior.']}, {'end': 815.175, 'segs': [{'end': 461.914, 'src': 'embed', 'start': 432.211, 'weight': 3, 'content': [{'end': 433.492, 'text': "But that's all I want you to know.", 'start': 432.211, 'duration': 1.281}, {'end': 436.254, 'text': "Now let's take a look at the out modifier.", 'start': 434.653, 'duration': 1.601}, {'end': 446.763, 'text': 'Now, out modifier is slightly similar to the ref modifier, in the sense that if a parameter is declared with the out modifier, as you see here,', 'start': 436.995, 'duration': 9.768}, {'end': 452.207, 'text': 'then in order for you to call that method, you also need to specify out when calling that method.', 'start': 446.763, 'duration': 5.444}, {'end': 456.29, 'text': 'But out is conceptually a little bit different from ref.', 'start': 453.308, 'duration': 2.982}, {'end': 461.914, 'text': 'What does it mean? That means with the out, this method can return a value to the caller.', 'start': 456.671, 'duration': 5.243}], 'summary': "The 'out' modifier is similar to 'ref' but returns a value to the caller.", 'duration': 29.703, 'max_score': 432.211, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU432211.jpg'}, {'end': 504.936, 'src': 'embed', 'start': 476.157, 'weight': 0, 'content': [{'end': 481.459, 'text': "And that's exactly where I say this is a code smell, or this is a design smell of the C sharp language.", 'start': 476.157, 'duration': 5.302}, {'end': 490.081, 'text': "Because if a method is going to return multiple values to the caller, it's better to encapsulate all these values into a separate class,", 'start': 482.159, 'duration': 7.922}, {'end': 492.201, 'text': 'which could be the return type of that method.', 'start': 490.081, 'duration': 2.12}, {'end': 498.772, 'text': 'So again I want to emphasize do not ever use the out modifier when designing your methods.', 'start': 493.649, 'duration': 5.123}, {'end': 504.936, 'text': 'but I included the out modifier here because there is one place in NET framework that you might be using sometimes.', 'start': 498.772, 'duration': 6.164}], 'summary': 'Encapsulate multiple return values into a separate class in c# to avoid using the out modifier in methods.', 'duration': 28.779, 'max_score': 476.157, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU476157.jpg'}, {'end': 586.114, 'src': 'heatmap', 'start': 557.473, 'weight': 0.875, 'content': [{'end': 560.055, 'text': "Now let's put this class in a separate file to clean up our code.", 'start': 557.473, 'duration': 2.582}, {'end': 566.52, 'text': 'So the cursor is here with resharper, we press alt and enter, and enter again.', 'start': 560.896, 'duration': 5.624}, {'end': 568.982, 'text': 'Now point is in a separate file.', 'start': 567.38, 'duration': 1.602}, {'end': 573.545, 'text': "Now let's add a method to move this point to a different location.", 'start': 570.503, 'duration': 3.042}, {'end': 582.852, 'text': 'So public void move, we need two parameters, an x and a y.', 'start': 574.185, 'duration': 8.667}, {'end': 586.114, 'text': 'And we simply change the value of our fields using these arguments.', 'start': 582.852, 'duration': 3.262}], 'summary': 'Moved class to separate file, added method to move point to new location.', 'duration': 28.641, 'max_score': 557.473, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU557473.jpg'}, {'end': 646.392, 'src': 'heatmap', 'start': 592.605, 'weight': 2, 'content': [{'end': 597.348, 'text': 'Now we can overload this method by creating another version of that that takes a different signature.', 'start': 592.605, 'duration': 4.743}, {'end': 599.629, 'text': 'Maybe the other one takes a point object.', 'start': 597.768, 'duration': 1.861}, {'end': 600.849, 'text': "Let's see how it works.", 'start': 600.029, 'duration': 0.82}, {'end': 603.431, 'text': 'So public void move.', 'start': 601.47, 'duration': 1.961}, {'end': 607.653, 'text': 'Here we pass a point object that is a new location.', 'start': 604.431, 'duration': 3.222}, {'end': 612.055, 'text': 'And we use this object to change the value of our field.', 'start': 609.534, 'duration': 2.521}, {'end': 616.598, 'text': 'So this.x equals new location.x.', 'start': 612.516, 'duration': 4.082}, {'end': 619.74, 'text': 'This.y equals new location.y.', 'start': 617.698, 'duration': 2.042}, {'end': 627.844, 'text': "Now let's go to our program class, so we simply press ctrl and tab to switch between open windows.", 'start': 622.321, 'duration': 5.523}, {'end': 629.044, 'text': 'There you go.', 'start': 628.604, 'duration': 0.44}, {'end': 639.589, 'text': "Let's create a point object, var point equals new point, and I give it an x and y, so 10 and say 20.", 'start': 629.624, 'duration': 9.965}, {'end': 646.392, 'text': "Now if we call the move method, point.move, look, we've got two versions of this method, so there are two overloads.", 'start': 639.589, 'duration': 6.803}], 'summary': 'Creating overloads for a method, using a point object, and demonstrating two versions of the method.', 'duration': 27.135, 'max_score': 592.605, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU592605.jpg'}, {'end': 756.746, 'src': 'embed', 'start': 699.682, 'weight': 1, 'content': [{'end': 701.183, 'text': 'So point.x, point.y.', 'start': 699.682, 'duration': 1.501}, {'end': 706.307, 'text': "Let's run the application with control and F5.", 'start': 704.246, 'duration': 2.061}, {'end': 713.431, 'text': 'Okay Point is at location 40 and 60.', 'start': 710.209, 'duration': 3.222}, {'end': 715.172, 'text': 'So our move method is working properly.', 'start': 713.431, 'duration': 1.741}, {'end': 718.594, 'text': "Now let's extend its example.", 'start': 717.313, 'duration': 1.281}, {'end': 722.136, 'text': 'And this time use the other overload of the move method.', 'start': 719.034, 'duration': 3.102}, {'end': 725.978, 'text': 'So point that move this time.', 'start': 722.796, 'duration': 3.182}, {'end': 728.599, 'text': 'I want to move it 200 and 200.', 'start': 726.018, 'duration': 2.581}, {'end': 729.96, 'text': 'So I use the second overload.', 'start': 728.599, 'duration': 1.361}, {'end': 736.768, 'text': "Again, let's copy paste this line here and make sure everything is working.", 'start': 733.024, 'duration': 3.744}, {'end': 738.469, 'text': 'We run the application.', 'start': 737.548, 'duration': 0.921}, {'end': 748.318, 'text': "Okay, so our point is moved twice and now it's at the location 100 and 200.", 'start': 741.132, 'duration': 7.186}, {'end': 749.799, 'text': 'So this is how overloading works.', 'start': 748.318, 'duration': 1.481}, {'end': 754.844, 'text': 'But I want to show you that there is a problem with this code in terms of best practices.', 'start': 750.68, 'duration': 4.164}, {'end': 756.746, 'text': "Let's get back to the point class.", 'start': 755.405, 'duration': 1.341}], 'summary': "The point class's move method was tested, and overloading was demonstrated, resulting in the point's location being moved to 100 and 200.", 'duration': 57.064, 'max_score': 699.682, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU699682.jpg'}], 'start': 409.042, 'title': 'Ref, out modifiers and overloading methods in c#', 'summary': 'Explains the differences between ref and out modifiers in c#, emphasizing the design smell of using out for methods returning multiple values. additionally, it covers the concept of overloading methods in c#, highlighting the importance of best practices to avoid code duplication and potential bugs.', 'chapters': [{'end': 498.772, 'start': 409.042, 'title': 'Ref and out modifiers in c#', 'summary': 'Explains the differences between the ref and out modifiers in c#, highlighting that while both require specifying the modifier when calling the method, out allows the method to return a value to the caller, emphasizing the design smell of using out for methods returning multiple values.', 'duration': 89.73, 'highlights': ['The out modifier in C# requires specifying the modifier when calling the method and allows the method to return a value to the caller.', 'The ref modifier in C# also requires specifying the modifier when calling the method, but it is different from out and does not allow the method to return a value to the caller.', 'The chapter emphasizes the design smell of using the out modifier when a method is going to return multiple values to the caller and suggests encapsulating the values into a separate class, which could be the return type of the method.']}, {'end': 815.175, 'start': 498.772, 'title': 'Overloading methods in c#', 'summary': 'Covers the concept of overloading methods in c#, demonstrating the creation of a point class with overloaded move methods, allowing for easier argument passing, and highlighting the importance of best practices to avoid code duplication and potential bugs.', 'duration': 316.403, 'highlights': ['The chapter demonstrates the creation of a point class with overloaded move methods, enabling easier argument passing and showcasing the practical implementation of overloading methods in C#.', 'The overloading of the move method allows for two different versions: one that takes a point object and another that takes separate x and y coordinates, enhancing the flexibility for the caller of the method.', 'The transcript emphasizes the importance of best practices in coding, highlighting the potential issues of code duplication and the recommendation to consolidate code to avoid potential bugs and simplify maintenance.']}], 'duration': 406.133, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU409042.jpg', 'highlights': ['The chapter emphasizes the design smell of using the out modifier when a method is going to return multiple values to the caller and suggests encapsulating the values into a separate class, which could be the return type of the method.', 'The transcript emphasizes the importance of best practices in coding, highlighting the potential issues of code duplication and the recommendation to consolidate code to avoid potential bugs and simplify maintenance.', 'The overloading of the move method allows for two different versions: one that takes a point object and another that takes separate x and y coordinates, enhancing the flexibility for the caller of the method.', 'The out modifier in C# requires specifying the modifier when calling the method and allows the method to return a value to the caller.', 'The ref modifier in C# also requires specifying the modifier when calling the method, but it is different from out and does not allow the method to return a value to the caller.', 'The chapter demonstrates the creation of a point class with overloaded move methods, enabling easier argument passing and showcasing the practical implementation of overloading methods in C#.']}, {'end': 1091.662, 'segs': [{'end': 906.515, 'src': 'heatmap', 'start': 868.19, 'weight': 0, 'content': [{'end': 869.351, 'text': 'We go back to the point class.', 'start': 868.19, 'duration': 1.161}, {'end': 873.66, 'text': 'Here we need to validate the argument that is passed in.', 'start': 871.078, 'duration': 2.582}, {'end': 876.261, 'text': "So we make sure that it's not null.", 'start': 874.32, 'duration': 1.941}, {'end': 882.004, 'text': "Otherwise, if we go null.x or null.y, we're going to get a null reference exception.", 'start': 876.581, 'duration': 5.423}, {'end': 893.851, 'text': 'We go if new location is null, we throw an argument null exception and pass the name of the parameter.', 'start': 882.925, 'duration': 10.926}, {'end': 901.73, 'text': 'What does this mean? First of all, Throwing an exception is a way to report errors to the caller.', 'start': 894.512, 'duration': 7.218}, {'end': 906.515, 'text': 'So here, I use the throw keyword, and here I create a new exception object.', 'start': 902.31, 'duration': 4.205}], 'summary': 'Validating argument in point class to avoid null reference exception and reporting errors using exceptions.', 'duration': 29.934, 'max_score': 868.19, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU868190.jpg'}, {'end': 982.212, 'src': 'embed', 'start': 956.467, 'weight': 1, 'content': [{'end': 962.551, 'text': 'But the difference is, this time we got an argument null exception as opposed to a null reference exception.', 'start': 956.467, 'duration': 6.084}, {'end': 968.957, 'text': "So you may argue, how is it different? Well, it's better to get an argument null exception than null reference exception.", 'start': 963.232, 'duration': 5.725}, {'end': 974.961, 'text': 'Why? First of all, your application should always have a global error handling mechanism.', 'start': 969.197, 'duration': 5.764}, {'end': 982.212, 'text': "The reason our application crashed here is because we don't have a global error handling or exception handling mechanism.", 'start': 976.109, 'duration': 6.103}], 'summary': 'Getting an argument null exception is better than a null reference exception due to the importance of having a global error handling mechanism.', 'duration': 25.745, 'max_score': 956.467, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU956467.jpg'}, {'end': 1049.019, 'src': 'embed', 'start': 1019.465, 'weight': 2, 'content': [{'end': 1022.586, 'text': 'which means some weird things may happen down the track.', 'start': 1019.465, 'duration': 3.121}, {'end': 1028.487, 'text': 'so the idea of defensive programming is to stop the program from getting into that weird or invalid state.', 'start': 1022.586, 'duration': 5.901}, {'end': 1036.391, 'text': "okay now, let me show you how we can improve this code by adding a global exception handling mechanism, so the application won't crash.", 'start': 1029.227, 'duration': 7.164}, {'end': 1038.791, 'text': "let's get back to our program.", 'start': 1036.391, 'duration': 2.4}, {'end': 1041.253, 'text': 'so simply, i add a try block here.', 'start': 1038.791, 'duration': 2.462}, {'end': 1043.714, 'text': 'you simply type try and press tab.', 'start': 1041.253, 'duration': 2.461}, {'end': 1045.356, 'text': 'let me show you again try tab.', 'start': 1043.714, 'duration': 1.642}, {'end': 1049.019, 'text': 'so again, this is a code snippet.', 'start': 1046.957, 'duration': 2.062}], 'summary': 'Defensive programming prevents program crashes by adding global exception handling.', 'duration': 29.554, 'max_score': 1019.465, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU1019465.jpg'}, {'end': 1091.662, 'src': 'embed', 'start': 1065.532, 'weight': 3, 'content': [{'end': 1071.457, 'text': 'i have covered the exception handling in more detail in my c sharp advanced course, but just to give you some tip here,', 'start': 1065.532, 'duration': 5.925}, {'end': 1080, 'text': 'what we need to do is We simply put a message on the console saying an unexpected error occurred.', 'start': 1071.457, 'duration': 8.543}, {'end': 1088.402, 'text': "Now if we run this application, the application doesn't crash and we get a friendly error message.", 'start': 1082.001, 'duration': 6.401}, {'end': 1091.662, 'text': 'This is better in terms of the user experience.', 'start': 1089.522, 'duration': 2.14}], 'summary': 'In c# advanced course, covered exception handling in detail. tip: display friendly error message to prevent application crash for better user experience.', 'duration': 26.13, 'max_score': 1065.532, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU1065532.jpg'}], 'start': 816.176, 'title': 'Null object exception handling', 'summary': 'Discusses handling null object exceptions in c# programming, emphasizing the importance of validating arguments to prevent null reference exceptions, and implementing defensive programming to improve code robustness. it demonstrates the addition of a global exception handling mechanism to prevent application crashes and provides reference to further learning resources on udemy.', 'chapters': [{'end': 928.111, 'start': 816.176, 'title': 'Handling null object exception', 'summary': 'Discusses handling null object exceptions in c# programming, emphasizing the importance of validating arguments to prevent null reference exceptions and explaining the use of exceptions for error reporting, with a reference to further learning resources on udemy.', 'duration': 111.935, 'highlights': ['The chapter discusses the importance of validating arguments to prevent null reference exceptions, highlighting the potential issue of passing a null object and the resulting null reference exception during program execution.', "The explanation of exceptions as .NET's way of error reporting and the use of the throw keyword for reporting errors to the caller, with a reference to a detailed course on exceptions in C# available on Udemy.", 'The demonstration of handling null object exceptions through code examples, showcasing the use of if statements to check for null objects and the throwing of argument null exceptions with the specific parameter name.']}, {'end': 1091.662, 'start': 928.111, 'title': 'Defensive programming and exception handling', 'summary': 'Discusses defensive programming to improve code robustness, emphasizing the importance of global error handling and exception mechanisms, and demonstrates the addition of a global exception handling mechanism to prevent application crashes.', 'duration': 163.551, 'highlights': ['Defensive programming aims to prevent the program from entering an unexpected or invalid state by immediately informing the caller of invalid input, thereby stopping further actions. This helps in avoiding unexpected behaviors and potential issues down the line.', 'Adding a global exception handling mechanism prevents the application from crashing and provides a better user experience by displaying a friendly error message instead of abruptly crashing.', 'The application crashed due to the absence of a global error handling mechanism, emphasizing the importance of having a robust error handling system in place to handle unexpected errors and exceptions.', 'Getting an argument null exception is preferable to a null reference exception as it communicates to the caller that the passed value is invalid, preventing further actions based on invalid input.']}], 'duration': 275.486, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU816176.jpg', 'highlights': ['The demonstration of handling null object exceptions through code examples, showcasing the use of if statements to check for null objects and the throwing of argument null exceptions with the specific parameter name.', 'The chapter discusses the importance of validating arguments to prevent null reference exceptions, highlighting the potential issue of passing a null object and the resulting null reference exception during program execution.', 'Defensive programming aims to prevent the program from entering an unexpected or invalid state by immediately informing the caller of invalid input, thereby stopping further actions. This helps in avoiding unexpected behaviors and potential issues down the line.', 'Adding a global exception handling mechanism prevents the application from crashing and provides a better user experience by displaying a friendly error message instead of abruptly crashing.']}, {'end': 1466.183, 'segs': [{'end': 1156.852, 'src': 'embed', 'start': 1091.822, 'weight': 0, 'content': [{'end': 1093.863, 'text': "You don't want to write an application that crashes.", 'start': 1091.822, 'duration': 2.041}, {'end': 1094.923, 'text': 'No one likes that.', 'start': 1094.223, 'duration': 0.7}, {'end': 1099.664, 'text': "Okay, I'm going to move all this code into a separate method.", 'start': 1096.323, 'duration': 3.341}, {'end': 1117.961, 'text': 'so static void, use points and i take everything here and pass it here.', 'start': 1101.727, 'duration': 16.234}, {'end': 1120.884, 'text': "okay, now let's go and create a calculator class.", 'start': 1117.961, 'duration': 2.923}, {'end': 1123.026, 'text': 'so public class calculator.', 'start': 1120.884, 'duration': 2.142}, {'end': 1130.368, 'text': 'We want to create a method called add that takes a varying number of arguments.', 'start': 1126.206, 'duration': 4.162}, {'end': 1133.289, 'text': 'So public int add.', 'start': 1130.968, 'duration': 2.321}, {'end': 1135.67, 'text': 'Here we add the params keyword.', 'start': 1134.29, 'duration': 1.38}, {'end': 1139.072, 'text': 'Params And then an integer array.', 'start': 1136.25, 'duration': 2.822}, {'end': 1141.993, 'text': 'And the name of the parameter is going to be numbers.', 'start': 1139.812, 'duration': 2.181}, {'end': 1147.327, 'text': 'Now inside this method, numbers is an integer array.', 'start': 1143.905, 'duration': 3.422}, {'end': 1153.43, 'text': "So let's say we have an integer array and we want to add all the numbers in that array together and return the result.", 'start': 1147.727, 'duration': 5.703}, {'end': 1156.852, 'text': 'First we create a variable called sum,', 'start': 1154.011, 'duration': 2.841}], 'summary': "Code is being refactored to create a 'calculator' class with an 'add' method that takes a varying number of arguments.", 'duration': 65.03, 'max_score': 1091.822, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU1091822.jpg'}, {'end': 1216.706, 'src': 'heatmap', 'start': 1171.274, 'weight': 0.799, 'content': [{'end': 1178.18, 'text': 'When you get to the advanced level, there is a better way to write this code, and that involves using link or language integrated query.', 'start': 1171.274, 'duration': 6.906}, {'end': 1180.542, 'text': "It's one of the powerful features of C sharp.", 'start': 1178.68, 'duration': 1.862}, {'end': 1182.904, 'text': 'Again, I have covered it in my C sharp advanced course.', 'start': 1180.602, 'duration': 2.302}, {'end': 1185.947, 'text': "So for now, let's just keep the code the way it is.", 'start': 1183.565, 'duration': 2.382}, {'end': 1188.489, 'text': 'Now we put this class in a separate file.', 'start': 1186.587, 'duration': 1.902}, {'end': 1190.891, 'text': 'So alt and enter and enter.', 'start': 1189.189, 'duration': 1.702}, {'end': 1193.853, 'text': "Now we're back to the program.", 'start': 1192.753, 'duration': 1.1}, {'end': 1199.018, 'text': "Let's create an instance of the calculator, var calculator.", 'start': 1195.235, 'duration': 3.783}, {'end': 1216.706, 'text': 'Now we can call the add method like passing two numbers, and we can simply display the result on the console, or we can pass three parameters or four,', 'start': 1202.264, 'duration': 14.442}], 'summary': 'C# advanced course covers powerful features like language integrated query.', 'duration': 45.432, 'max_score': 1171.274, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU1171274.jpg'}, {'end': 1276.603, 'src': 'embed', 'start': 1219.483, 'weight': 2, 'content': [{'end': 1224.529, 'text': "can pass a varying number of parameters, and that's the effect of the params keyword.", 'start': 1219.483, 'duration': 5.046}, {'end': 1231.297, 'text': 'we can also call this method using an array notation, so let me paste that again here.', 'start': 1224.529, 'duration': 6.768}, {'end': 1236.178, 'text': 'instead, i can pass a new integer array and put all numbers here.', 'start': 1231.297, 'duration': 4.881}, {'end': 1244.282, 'text': "But as you see, it's easier to simply pass all the parameters without the need to create an integer array.", 'start': 1237.218, 'duration': 7.064}, {'end': 1246.324, 'text': "And that's why we use the params keyword.", 'start': 1244.763, 'duration': 1.561}, {'end': 1250.946, 'text': "Okay, let's put this code in a separate method and move to our third example.", 'start': 1247.304, 'duration': 3.642}, {'end': 1253.848, 'text': "So I'm going to create another static method here.", 'start': 1251.667, 'duration': 2.181}, {'end': 1256.75, 'text': 'Use params.', 'start': 1255.489, 'duration': 1.261}, {'end': 1260.092, 'text': "Let's move everything here.", 'start': 1258.611, 'duration': 1.481}, {'end': 1267.596, 'text': 'The third example involves using the out modifier.', 'start': 1264.654, 'duration': 2.942}, {'end': 1271.96, 'text': 'I told you, do not use the out modifier when declaring your methods,', 'start': 1268.217, 'duration': 3.743}, {'end': 1276.603, 'text': 'but there are cases in the NET framework where you may have to use the out modifier.', 'start': 1271.96, 'duration': 4.643}], 'summary': 'Using params keyword for passing varying number of parameters and the use of out modifier in .net framework.', 'duration': 57.12, 'max_score': 1219.483, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU1219483.jpg'}, {'end': 1417.25, 'src': 'embed', 'start': 1384.527, 'weight': 4, 'content': [{'end': 1390.594, 'text': 'Now, how is it different from the parse method? The difference is try parse does not throw an exception.', 'start': 1384.527, 'duration': 6.067}, {'end': 1396.82, 'text': "And that's the reason it returns a Boolean to indicate whether the conversion was successful or not.", 'start': 1391.675, 'duration': 5.145}, {'end': 1403.526, 'text': 'The downside is that you have to declare this integer separately and then use the out modifier.', 'start': 1398.001, 'duration': 5.525}, {'end': 1407.948, 'text': "some people don't like the try parse method and they prefer to use parse.", 'start': 1404.267, 'duration': 3.681}, {'end': 1417.25, 'text': 'but then you have to handle exception using a try catch block, as we learned a little bit earlier, something like this.', 'start': 1407.948, 'duration': 9.302}], 'summary': 'Try parse method returns boolean, avoids exception. downside: separate declaration and out modifier for integer.', 'duration': 32.723, 'max_score': 1384.527, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU1384527.jpg'}], 'start': 1091.822, 'title': 'C# calculator class and methods', 'summary': "Demonstrates creating a calculator class in c#, defining a method to add varying arguments using 'params' keyword and a for each loop. it also covers the usage of out modifier, parse method, and try parse method for exception handling in c#.", 'chapters': [{'end': 1182.904, 'start': 1091.822, 'title': 'Creating a calculator class in c#', 'summary': "Demonstrates creating a calculator class in c# and defining a method to add a varying number of arguments, showcasing the use of the 'params' keyword and a for each loop, and mentioning the use of language integrated query at the advanced level.", 'duration': 91.082, 'highlights': ["The chapter demonstrates creating a calculator class in C# and defining a method to add a varying number of arguments, showcasing the use of the 'params' keyword and a for each loop, and mentioning the use of language integrated query at the advanced level.", "The method 'add' in the calculator class takes a varying number of arguments using the 'params' keyword and operates on the integer array to return the sum of all the numbers.", 'It mentions that at an advanced level, there is a better way to write the code using language integrated query, a powerful feature of C#.']}, {'end': 1466.183, 'start': 1183.565, 'title': 'C# methods and parameters', 'summary': 'Covers the usage of params keyword for passing a varying number of parameters, the use of out modifier for method declaration, and the comparison between parse method and try parse method for exception handling in c#.', 'duration': 282.618, 'highlights': ['The chapter covers the usage of params keyword for passing a varying number of parameters. The chapter explains the usage of the params keyword for passing a varying number of parameters to methods in C#.', 'The use of out modifier for method declaration is demonstrated. The chapter demonstrates the use of the out modifier for method declaration and provides an example of using the out modifier to convert a string to a number without throwing an exception.', 'The comparison between parse method and try parse method for exception handling in C# is discussed. The chapter discusses the differences between the parse method and the try parse method for exception handling in C#, highlighting that try parse does not throw an exception and returns a Boolean to indicate the success of the conversion.']}], 'duration': 374.361, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/56bbjE4assU/pics/56bbjE4assU1091822.jpg', 'highlights': ["The method 'add' in the calculator class takes a varying number of arguments using the 'params' keyword and operates on the integer array to return the sum of all the numbers.", "The chapter demonstrates creating a calculator class in C# and defining a method to add a varying number of arguments, showcasing the use of the 'params' keyword and a for each loop.", 'The chapter covers the usage of params keyword for passing a varying number of parameters.', 'The use of out modifier for method declaration is demonstrated.', 'The comparison between parse method and try parse method for exception handling in C# is discussed.']}], 'highlights': ['The chapter covers method signature, method overloading, and three modifiers: params, ref, and out, with a focus on params as the only useful modifier.', 'The benefits of overloading are highlighted, such as simplifying the usage of a class by providing different method signatures, making it easier for consumers to choose the right overload based on the parameters they have, with examples of overloads for different parameter types and a third overload for creating animations.', 'The chapter emphasizes the design smell of using the out modifier when a method is going to return multiple values to the caller and suggests encapsulating the values into a separate class, which could be the return type of the method.', 'The demonstration of handling null object exceptions through code examples, showcasing the use of if statements to check for null objects and the throwing of argument null exceptions with the specific parameter name.', "The method 'add' in the calculator class takes a varying number of arguments using the 'params' keyword and operates on the integer array to return the sum of all the numbers."]}