Creating and Calling Simple Overloaded Helper Methods - 10
- Posted: Nov 21, 2011 at 9:13 AM
- 65,904 Views
- 36 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
In this video we begin wading into the topic of methods by creating a helper method to break out code we may need to use in multiple places within our code. We create and call our methods to retrieve a value, create and use input parameters, learn about string formatting, and create overloaded versions of our method
Already have a Channel 9 account? Please sign in
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Overloading i learnt today, which i never able to understand going through other site. period.
i can't download any vidoes, it says your servers are down! please put it back up
Thanks... The servers are back i can now download this videos
Just a quick question is there a reason why the methods were written after the program code? Can you write methods first and then call them later?
Thanks.
@Kevin: GREAT QUESTION! First, you can always try stuff like this out on your own -- and you should! It's a great way to learn the propensities of the environment you're in. In this case, it does not matter -- you can put the code anywhere. What matters, as you'll learn soon, is the NAME of the method, both it's method name AND the namespace it belongs to. The compiler is smart enough to link up a method call -- regardless of where it's defined -- with its definition. Again, love that question!
Great, just a question. Is any video where you explain ref, out and arrays params for methods? Thanks Bob, your videos and the way how u explain the topics are easy to understand.
@claudioas2001: Out parameters, yes. At some point we talk about TryParse and in that video, TryParse will send a converted value as an output parameter. Unfortunately, I can't recall which video that is in ... someone recently asked for help with it, so look for a long passage / reply from me on TryParse. It's a simple concept however ... output parameters are a second way to return values from methods (the other way being the 'return' statement). Just prefix a parameter with out, like so:
re: using arrays as input parameters. Personally, I hate arrays for passing data around in real applications. I much prefer using generic collections. I believe I do talk about generic collections near the end of this series and in more depth on my website (see the C# for Absolute Beginner's series, day 5). Hope that helps!
Bob,
Regards from Ireland!
Loved your videos, you are a fantastic teacher. Where would you recommend to go from here as far as learning materials go?
Thanks for the great series!
Kieran
Bob, while wandering through so many programming courses, I have long strugled to understand basics of programing. Bob, you are simply best!!
I love the length of these videos. It's great to throw a little quick learning in every day. Thanks!
@Kieran: Sorry for the delayed response. I'm constantly creating new content / entire courses on my own site if you like my style. www.learnvisualstudio.net ... hope I can help! -Bob
Thank you,Bob; you are a fantastic teacher, and the content is A+++. You take a subject which is like Greek to the neophyte and make it logical and understandable. 5 Stars!!!
Thank you,BoB.
all videos are ********
thanks bob
@Bill: @paekyaw: Thank you, much appreciated.
@raju: I hope ******* is a good thing?
just got to understand the concept of overloading...thanks bob you make it seem so simple and straight forward..
Thank you for the video.
thanx..BoB..
Why doesn't this work? I'm probably doing something stupidly wrong.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestingTesting
{
class Program
{
static void Main(string[] args)
{
string[] names = {"Bobby", "Steve", "Chad", "Bart"};
foreach (string name in names)
Console.WriteLine(name);
Console.WriteLine("");
Console.WriteLine("Press any key to continue.");
Console.ReadLine();
string numberChoice;
Console.WriteLine("Choose a number between 0 and 3:");
numberChoice = Console.ReadLine();
string myValue = superSecretFormula(names[numberChoice]);
Console.WriteLine(myValue);
Console.ReadLine();
}
private static string superSecretFormula(string name)
{
return string.Format("Hello World, and {0}.", name);
}
}
}
@DDom23: What is the error message you are getting? Which line does the error message reference? Or are you simply getting results you did not anticipate?
Its ok now. I forgot that readline forms a string and had to convert it using convert.toint32 before I could use it.
Hi Bob,
Order of parameters also matters, for example
SuperSecretFormula(string name, int age) is different from
SuperSecretFormula(int age, string name)
So Number, Type and Order of parameters are considered in Method overloading.
Thanks
@Dinesh: Yep, order matters.
Tenho grande dificuldade no ingles... Mas quem quer consegue.
WHOA! I just wanna say I got my start watching your videos back when I started programming in '08, it's awesome to see you again!
Hi bob,
your tutorial is great. i am in need of creating an app for tablet running windows 7 OS. what all tools or SDK's will i need to set up before creating one other than visual studio?? and if a Winforms app enough to run on tablet?? i need your help in that..thanks in advance...
@JG Hayes:Awesome ... are you still writing code? Let me know what you're up to!
@NIthin: I'm really sorry, but I have absolutely no knowledge in what you're asking. If it's an old-style tablet it should "just work" ... the OS takes care of pen / virtual keyboard input ... I think. Again, I'm not the guy to ask about that. Sorry!
Hi bob
I am just a beginner in Programming well i saw your few videos and i would like to be learn c sharp .Please if you would recommend me to go through your video which will help me to learn c sharp for future.
@Akram: Hi, I may not completely understand what you are asking. However, I would say just start here and watch them all, and be sure to follow along. Once you finish this entire series, you'll have the basics and can move on to learn more about (1) composing classes / delegating responsibilities / designing interactions, etc. (2) the .NET Framework APIs for things like data access, some front end client technology like WPF or ASP.NET WebForms or MVC. Could you clarify your question? I'd be glad to point you in the right direction if I can.
Hi Bob,
Thanks for putting so much efforts and making these videos. The videos are awesome.
@DDom23: Error is in the below line
string myValue = superSecretFormula(names[numberChoice]);
numberChoice is an string variable, You need to use int.Parse method to covert it into int. replace that code with below.
string myValue = superSecretFormula(names[int.Parse(numberChoice)]);
How can i download core c# course complete videos??
Hi Bob,
I have been going through your video every chance I get, all day long when possible.
Its very rewarding and comprehensible. Although, the "Buffering" is annoying. What can I do, other than pausing it for the buffering to catch up? It interferes with my train of thought, especially when you are sharing a new concept for me.
@Bilal
I would like to download the video as well and have been unsuccessful.
Great Lesson on calling the same method with different versions. I can already see how to apply this in a real world setting.
I love your holly videos, you are the only fantastic C# God for me as I am just a zero beginner and watched your videos for WinPhon7! I have already coded one application...
I love your holly videos, you are the only fantastic C# God for me as I am just a zero beginner and watched your videos for WinPhon7! I have already coded one application...
Remove this comment
Remove this thread
close