11 December 2011

C# Lesson 11 : Creating and Calling Simple Overloaded Helper Methods

Now, 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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelperMethods
{
    class Program
    {
        static void Main(string[] args)
        {
            //string myValue = superSecretFormula("world");
            string myValue = superSecretFormula("sunshine");
            Console.WriteLine(myValue);
            Console.ReadLine();
        }

        private static string superSecretFormula()
        {
            // some cool stuff here
            return "Hello World!";
        }

        private static string superSecretFormula(string name)
        {
            return String.Format("Hello, {0}!", name);

        }

    }
}
Source : MS Virtual Academy

No comments: