Thursday, November 13, 2014

C# Beginner Code practice

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp20141113
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your last name");
            string SomeDatafromUser = Console.ReadLine();
            try
            {
                if (SomeDatafromUser.Length > 10)
                {
                    throw new Exception("Name should not be greater than 10 characters");
                }
                Console.WriteLine("Hello " + SomeDatafromUser);
                Console.WriteLine("hello again");
                Console.ReadLine();
                Console.WriteLine("Enter your age");
                int Age = 0;
                Age = Convert.ToInt16(Console.ReadLine());
                Console.WriteLine("Hello Mr " +SomeDatafromUser+" your age is "+ Age );
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
                Console.ReadLine();
            }
        }
    }
}

No comments:

Post a Comment