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();



        }

    }

}


Difference between Call by value and Call by Reference





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication4

{

    class Program

    {

        public void sum(float a, float b)

        {

           float x=a + b;

           Console.WriteLine(x);

        }



        public int changevalue(int x)

        {

            x = x * x;

            return x;

        }

        public int changereference(ref int x)

        {

            x = x + x;

            return x;

        }

       

        static void Main(string[] args)

        {

            Program p = new Program();

            int a = 5;

            Console.ForegroundColor = System.ConsoleColor.Red;

            Console.WriteLine("call by value ..............................");

            Console.ForegroundColor = System.ConsoleColor.White;

            Console.WriteLine("value from function " + p.changevalue(a));

            Console.WriteLine("actual value of a = "+a);

            Console.ForegroundColor = System.ConsoleColor.Red;

            Console.WriteLine("call by Reference ..............................");

            Console.ForegroundColor = System.ConsoleColor.White;

            Console.WriteLine("output from function : " + p.changereference(ref a));

            Console.WriteLine("actual value of a = " + a);

            Console.ReadLine();

       

        }

    }

}


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