Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Part 17 - C# Tutorial - Method parameters


Part 17 - C# Tutorial - Method parameters


13 comments:

  1. Hi Venkat,
    Why you define Out parameter like this because Ref also can do the same(return multiple values to you)?
    I mean Ref also full fill the same..

    -Sanjay

    ReplyDelete
  2. We need to initialize the variable used in case of Ref but this does not apply for OUT

    ReplyDelete
  3. using System;


    class Program
    {
    public static void main()
    {

    int i = 0;
    simplemethod(i);

    Console.WriteLine(i);
    Console.ReadKey();
    }

    public static void simplemethod(int j)
    {
    j=101;
    }

    }



    the above program ives me error as program does not contains static main method..........plz help

    ReplyDelete
    Replies
    1. Yes, you do not have a "Main" method. Just casing issue.

      Delete
    2. Write main as Main ..Your problem will be solved.

      Delete
    3. Its too late
      You have pass the parameter in main method

      Delete
    4. The name of the method should be "Main"
      it shouldn't be main.............
      check it will work

      Delete
  4. Love you Venkat, You're the best

    ReplyDelete
  5. sir how change order of output parameter in time of calling as like mssql

    ReplyDelete
  6. why to use params keyword can't we directly pass an array as parameters?

    ReplyDelete
  7. class Program
    {
    static void Main(string[] args)
    {
    double areas = 0;

    double cir = 0;
    Program.calculate(5, out areas, out cir);
    Console.WriteLine("the area is {0}", areas);
    Console.WriteLine("the circumfrence is {1}",cir);
    }
    public static void calculate(double radious, out double area,out double circum)
    {
    area = Math.PI * Math.Pow(radious, 2);
    circum = 2 * Math.PI * radious;
    }

    ReplyDelete
    Replies
    1. using System;
      namespace helloWorldApplication
      {
      class Program
      {
      static void Main(string[] args)
      {
      double areas = 0;

      double cir = 0;
      Program.calculate(5, out areas, out cir);
      Console.WriteLine("the area is {0}", areas);
      Console.WriteLine("the circumfrence is {0}", cir);
      Console.ReadKey();
      }
      public static void calculate(double radious, out double area, out double circum)
      {
      area = Math.PI * Math.Pow(radious, 2);
      circum = 2 * Math.PI * radious;
      }
      }
      }

      use this modified program to get efficient output

      Delete
  8. this program compile successfully but at the run time it shows the error with the circumfrence...please help me sir..for short it out

    ReplyDelete

It would be great if you can help share these free resources