Aim:

   To perform the command line argument program using c sharp.net application.

Algorithm:

Step1: Start the program.

Step2: Open the new text document.

Step3: Type the program and create a class name as program name.

Step4:  Assign the arguments as a parameters inside and outside of the program.

Step5:  Save the program with the extensions of .cs

Step6:  Compile the program.

Step7: Run the program.

A) Argument with String 



using System;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

namespace ConsoleApplication1

{

class Program

    {

static void Main(string[] args)

        {

Console.Write("welcome");

Console.Write(" "+args[0]);

Console.Write(" " + args[0]);

Console.ReadLine();

        }

    }

}


OUTPUT:



B) Argument with Number


using System;

classCommandLineArgs

{
public static void Main(String[] args)

    {

double a, b;

if (args.Length == 0)

        {

Console.WriteLine("No arguments found");

        }

else

        {

            a = double.Parse(args[0]);

            b = double.Parse(args[1]);

double sum = 0, mul = 0, div = 0, sub = 0;

sum = a + b;

Console.WriteLine("Sum of " + a + " + " + b + " is " + sum);

sub = b - a;

Console.WriteLine("Subtraction of {0} - {1} is {2}", b, a, sub);

mul = a * b;

Console.WriteLine("Multiplication of " + a + " * " + b + " is " + mul);

div = a / b;

Console.WriteLine("Division of " + a + " / " + b + " is " + div);

Console.Read(); 

        }

    }

}



OUTPUT:



BY
    REGU RAM SV.

Post a Comment

أحدث أقدم