VB.NET 2013: Parameters - ByRef vs ByVal, Optional and Arrays
HTML-код
- Опубликовано: 3 окт 2024
- The basics playlist covers the essential skills and knowledge you'll need to program in VB.NET. This video covers the following features:
Reintroduction to Parameters
ByVal vs ByRef
Optional Parameters
Passing an Array as a parameter
Previous Parameter Video: • VB.NET 2013 - Subs, Fu...
As always any comments or suggestions please drop a line!
Thanks mate you are helping me getting my A level in computer science. Thanks for the tutorials with OOP as well
Your channel is really underrated.
Good Job man, your teaching skills really show in your ability to provide good lessons for understanding this stuff. Your vids are Awesome!
Thanks mate!
Amazingly informative and endearing, thank you for the video!
Fantastic tutorial, thanks!
thank's for that nick, and I do intend to keep programming!
Very cool explained...
Two things:
1. When I hit the return key to avoid entering a third number, it throws an error because a put "" string in the single variable.
2. In cases where there are multiple optional parameters, how do you pass say the 2nd optional parameter. How do you let the function or sub know that it wasn't intended for the first optional parameter?
Thanks for the videos Nicholas. Love them.
+michael fraker
1) To avoid this type of error, accept the ReadLine input into a String, instead of an Integer/Float. Then try to convert the String variable to an Integer, such as:
Dim num3 As Integer
Dim input3 As String = Console.ReadLine()
If IsNumeric(input3) Then
num3 = CInt(input3)
End If
2) If you want to skip the first optional parameter you leave it blank, insert your comma and then insert the value for the second parameter. For example:
AddNums(, 5)
how is the function returning 2 values? total and avg. i dont get that
Nicholas, I have gotten a little confused. Ok so in the part where we use arrays and we have a for loop why do we - 1 it kinda doesn't make sense to me?
Great question as you'll be seeing the -1 lots and lots if you keep programming.
Here's an example for you, if I have an Array with 10 items then they aren't numbered 1, 2, 3, 4... 10; they are numbered 0, 1, 2... 9.
So in my For loop I repeat from 0 to Array.Length -1, which would look like For i = 0 to 10 - 1 THUS becoming For i = 0 to 9.
I hope that helps.
nice
you use in num3 optional -1 as not include value so what if the user try to chose this value in his calculation of example i need average for( 5, 7, -1)? bad luck can happen ))
+haydar M.Al-samawe Yeah pretty much would be bad luck in this case. I use this for tutorials because it's much easier to understand. However, in my own programs I'd probably look at a nullable primative instead of the -1 value.