Hi,
I have 3 class files.
namespace M
{
class Add
{
static void Main(string[] args)
{
Add();
}
Public static void Add()
{
int a=10;
int b=10;
int c=a+b;
}
}
}
namespace N
{
class Mul
{
static void Main(string[] args)
{
Mul();
}
Public static void Mul()
{
int a=10;
int b=10;
int c=a*b;
}
}
}
namespace P
{
class Mul
{
static void Main(string[] args)
{
Sub();
}
Public static void Sub()
{
int a=10;
int b=10;
int c=a-b;
}
}
}
Above three class file i have to use in another class file i.e
Here i need to pass Arguments using Command Line, so how to pass arguments to the below class.
If i pass argument /add then first case statement to be executed.
If i pass argument /Multhen second case statement to be executed.
If i pass argument /Sub then third case statement to be executed.
namespace Maths
{
class Mathematics
{
static void Main(string[] args)
{
foreach(string str in args)
{
GetAllTasks(str);
}
}
Public static void GetAllTasks(string str)
{
switch(args)
{
case "/add":
"Here i need to execute the First Class Method ADD()"
case "/Mul":
"Here i need to execute the Second Class Method Mul()"
case "/sub":
"Here i need to excute the third class method Sub()"
break;
}
}
}
}
Please help me....
Jignesh TrivediPosted Feb 29, 2012, 10:49 PM
try,
namespace M
{
class Addition
{
static void Main3(string[] args)
{
Add();
}
public static void Add()
{
int a = 10;
int b = 10;
int c = a + b;
}
}
}
namespace N
{
class Multification
{
static void Main1(string[] args)
{
Mul();
}
public static void Mul()
{
int a = 10;
int b = 10;
int c = a * b;
}
}
}
namespace P
{
class Substraction
{
static void Main2(string[] args)
{
Sub();
}
public static void Sub()
{
int a = 10;
int b = 10;
int c = a - b;
}
}
}
namespace Maths
{
class Mathematics
{
static void Main(string[] args)
{
foreach (string str in args)
{
GetAllTasks(str);
}
}
public static void GetAllTasks(string str)
{
switch (str)
{
case "/add":
M.Addition.Add();
break;
case "/Mul":
N.Multification.Mul();
break;
case "/sub":
P.Substraction.Sub();
break;
}
}
}
}
hope this is ans of your que.
SenthilkumarPosted Feb 29, 2012, 10:47 PM
The arqument list in the C# console application is used to get the input from the users at the time of execution.
class Example {
{
public static void Main(string[] args)
{
int len = args.length;
for(int i=0;i
Console.WriteLine("Argument {0} is {1}",i.ToString(),args[i]);
}
}
}
After compiling like this
csc Example.cs
You will get the execution file(IL).
then you need to execute like the following.
example Hai Welcome To C# language
then args lenth will be 5.