Programming Course in C# ¡Free!

Parameters of Main, Sum

 Saturday, April 06, 2013 published by Exercises C#
Proposed exercise

Create a program named "sum", which receives two integer numbers in the command line and displays their sum, as in this example:

sum 5 3
8

Output



Solution


using System;
public class ParamsOfMain
{
public static void Main(string[] args)
{
if ( args.Length == 2)        
Console.WriteLine(Convert.ToInt32(args[0]) +
Convert.ToInt32(args[1]) );
else
Console.WriteLine("Two numbers");
}
}