Wednesday, 2 May 2018

Out parameter Function in C#









using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication5

{

    class Program

    {

        public float calavg(int a,int b,int c,out int sum)

        {

            sum = a + b + c;

            return sum / 3;

       

        }





        public float calavg2(int a, int b, int c, ref int sum)

        {

            sum = a + b + c;

            return sum / 3;



        }





        static void Main(string[] args)

        {

            Program p=new Program();

            int d1=54, d2=78, d3=100,s=0;

            float avg;



           /* avg = p.calavg(d1, d2, d3,out s);

            Console.WriteLine("total score is "+s);

            Console.WriteLine("avg score is "+avg);

            */



         avg=   p.calavg2(d1, d2, d3, ref s);



            Console.WriteLine("total score is " + s);

            Console.WriteLine("avg score is " + avg);

            Console.ReadLine();



        }

    }

}


No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...