C# input output example

This is a little Program written in C sharp with Mono, It reads a number from the Terminal multiplies with itself and then print back:

using System.IO;
using System;

class Program
{
    static void Main()
    {
        Console.Write("write your number: ");//Info text 
        String str = Console.ReadLine();//read input
        Console.WriteLine("your number: "+str);//print input
        int i = Convert.ToInt32(str);//convert to intager
        i = i*i;//calculate
        Console.WriteLine("your result: "+i);//print result
    }
}

To compile run this:

mcs *.cs -out:main.exe

And then start with Mono :

mono main.exe

our result looks like this:

write your number: 4   
your number: 4     
your result: 16

The same Programm in Java is here : Java input output example

4 thoughts on “C# input output example”

  1. I love what you guys are usually up too. This sort of clever work and exposure!
    Keep up the fantastic works guys I’ve added you guys to my own blogroll.

Leave a Reply

Your email address will not be published.

five × 4 =