Parameters of Main, Sum Learn programming C#



Lesson:

Functions


Exercise:

Parameters of Main, Sum


Objetive:

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


Code:

using System;
public class exercise112
{
    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, please");
    }
}



Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.