Saturday, June 28, 2014

C# Tutorial for Beginners 13 - Passing Reference , Output and params Pa...





Passing Reference Parameter 



using System;
namespace MyProject.Examples
{
    class ExampleOne
    {
        public static void Main()
        {
            int y = 0;
            MyFunc(ref y);

            Console.WriteLine(y);


            Console.ReadKey();
        }

        public static void MyFunc(ref int x)
        {
            x = 10;
        }

    }
}






Passing Output Parameter 



using System;
namespace MyProject.Examples
{
    class ExampleOne
    {
        public static void Main()
        {
            int a=45,b=67;
            int sum = 0;
            int product = 0;
            MyCalc(a, b, out sum, out product);

            Console.WriteLine("Sum = {0} and Product ={1}", sum,product);


            Console.ReadKey();
        }

        public static void MyCalc(int x, int y, out int sum, out int prod)
        {
            sum = x + y;
            prod = x * y;
             
        }

    }
}






Passing params Parameter 



using System;
namespace MyProject.Examples
{
    class ExampleOne
    {
        public static void Main()
        {
            string[] myArray = new string[4];
            myArray[0] = "name1";
            myArray[1] = "name2";
            myArray[2] = "name3";
            myArray[3] = "name4";

            ArrayMethod();
            //or
            ArrayMethod(myArray);
            //or
            ArrayMethod("n1","n2","n3");

            Console.ReadKey();
        }

        public static void ArrayMethod(params string[] names)
        {
           foreach(string name in names)
           {
               Console.WriteLine(name);
           }
           Console.WriteLine("Array Size = {0}", names.Length);
             
        }

    }
}


















------------------------------------------------------------------

Searches related to method output parameters and return in c#

c# method return 2 variables

c# - How to pass a single object[] to a params object[]

C# Passing arguments by default is ByRef instead of ByVal

Searches related to pass by params parameters in c#

c# pass variable number of arguments

c# pass arguments by reference

 c# pass arguments

c# pass arguments to main

c# timer pass arguments

c# pass arguments to thread

pass arguments to exe c#

c# pass arguments to process

How are parameters passed in C#

C# Parameter Passing, Ref and Out

c# method return multiple variables

c# stored procedure output parameters

return output parameter stored procedure c#

c# call stored procedure with output parameters

c# function output parameter

Passing Parameters

Passing Objects By Reference or Value in C#
IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ