Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-11-2009
Member
 
Join Date: Sep 2009
Posts: 143
Variable method arguments in Csharp

I have just started studying Csharp as it is in my syllabus. I have the experience of using Java in my earlier term. And this is helping me to study Csharp. My doubt is, are Variable method arguments supported in Csharp? I am not having any knowledge about this. I tried but, I am not getting a satisfactory answer. Can anyone please provide a precise explanation on this ?
Reply With Quote
  #2  
Old 14-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Variable method arguments in Csharp

The answer to your question is that with the use of keyword params it is possible to have a Variable method arguments in Csharp. On a method parameter which is an array we can apply the keyword params. By seperating the element list of an array by comma(,) we can supply them on method invocation.
eg:

Code:
void Disp(params object[] info)
{
   foreach (object I in info)
   Console.WriteLine(I);
}
PrintOut("Hi", new DateTime(14, 11, 2008), 8);
Reply With Quote
  #3  
Old 14-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Variable method arguments in Csharp

I had just completed Csharp basics. I also had hard time learning Csharp. I didnot had any knowledge of Java although I have studied HTML(Hyper Text Markup Language) which was of no use here. One of the features of Csharp is that it enables you to have variable method arguments in Csharp. You can achieve this by using the params keyword.
Reply With Quote
  #4  
Old 14-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Variable method arguments in Csharp

Code:
using System;
 
class varpar
{
   public static void out(params int[] anum)
   {
      foreach(int num in anum)
      {
         Console.WriteLine(num); 
      }
   }
 
   public static void Main (string[] args)
   {
      out(5, 21, 8);  
   }
}
From the above C# code it is very clear that C# supports variable method arguments. Thus a method in C# can have a variable argument list by making use of the params keyword. This is also a common feature between C# and Java.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Variable method arguments in Csharp"
Thread Thread Starter Forum Replies Last Post
How to input variable in string.find method in C++ Caelaan Software Development 5 29-01-2010 10:50 PM
String in the method arguments DANIEL 602 Software Development 3 29-12-2009 02:21 PM
Function with a variable number of arguments Chrisch Software Development 3 20-11-2009 02:03 PM
Syntax Error for a variable named checked in Csharp KANAN14 Software Development 3 17-11-2009 01:58 AM
How to pass arguments to the main method Wannabe Software Development 3 12-09-2009 11:51 AM


All times are GMT +5.5. The time now is 06:40 AM.