Press "Enter" to skip to content

C#

C# , is a language which Microsoft developed. C# was made by being influenced by Java and C++ programming language. C# improved the things which you can do using by the C or C++.  For coding using with the C# , I will use the Visual Studio. You can click here for the install Visual Studio. I can do everything which i did in C with the C#.

There are some terms we have to know;

Console.Write(): Using with this term ,we can press screen what you wanna press on the same line.

Console.Writeline(): Using with this term ,we can press screen what you wanna press on the different line.

Console.ReadLine(): Using with this term , we get the number or character from the user.

Console.ReadKey():  We use this term for the program stay on the screen.

I will make very simple program. I will press ‘Hello World’ on the screen. Code Syntax;

using System;

namespace WebDers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
            Console.ReadKey();
        }
    }
}

Screen Output;

Hello World

I will make the another simple program which is getting number from the user and press it the screen. Code Sytnax;

using System;

namespace WebDers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter a number:");
// I defined the variable and for the get number from user , I used int.parse
            int number = int.Parse(Console.ReadLine());
            Console.WriteLine("" + number);
// for the press on scree , i use + and variable name
            Console.ReadKey();
        }
    }
}

Screen Output;

Enter a number:49
49

Now , I will make a program using with the loops. Logic is absolutely same . We can use like using with C . Program will get 2 numbers from the user and program will press the numbers between the number in these numbers on the screen.  Code Syntax;

using System;

namespace WebDers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the first number:");
            int number1 = int.Parse(Console.ReadLine());
            Console.Write("Enter the second number:");
            int number2 = int.Parse(Console.ReadLine());
            if (number1 > number2)
            {
                for (; number2 < number1; number2++)
                {
                    Console.Write(" " + number2);
                }
            }
            else
            {
                for (; number1 < number2; number1++)
                {
                    Console.Write(" " + number1);
                }
            }
            Console.ReadKey();
        }
    }
}

Screen Output ;

Enter the first number:25
Enter the second number:18
 18 19 20 21 22 23 24

 

 

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *