Tuesday, 24 January 2017

METHODS

Methods can have attributes, access modifiers, return types, method names, parameters and methods..

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

namespace ConsoleApplication3
{
    class Program
    {

        static void Main(string[] args)
        {
            Program p = new Program();
            p.EvenNumbers();
            int Sum = p.Add(10, 20);
            Console.WriteLine("Sum={0}", Sum);
            Console.ReadLine();
        }

        public int Add(int F ,int L)
        {
            return F + L;
        }
 
        public void EvenNumbers()
        {
            int start = 0;

            while (start <= 20)
            {
                Console.WriteLine(start);
                Console.ReadLine();
                start = start + 2;
             
            }
        }
    }
}
         
================
OUTPUT PARAMETERS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {

        static void Main(string[] args)
        {
            int Total = 0;
            int Product = 0;
            Calculate(10, 20, out Total, out Product);
            Console.WriteLine("sum = {0} && product = {1}",Total,Product);
            Console.ReadLine();

        }

        public static void Calculate(int FN, int LN, out int sum, out int product)
        {
            sum = FN + LN;
            product = FN * LN;
        }

    }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.