Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, October 4, 2013

Programming Example of creating class in C#






C# Program to creating class 
In this csharp tutorial guideline while creating class
1. The class name should be noun and meaningful.
2. Use either pascal case or camel case. In camel case, the first letter is small. Ex. camelCase. In pascal case first letter is capital. Ex. PascalCase. It is strictly recommended you to use pascal case for class name and camel case for variable name.
3. Your class name should not contain any special character except underscore (_) or digit. Must start your class name with character.
4. Don’t use reserved keyword for class name.
Then we show the result in output
For this we use console readline and console write line



Program :

using System;


namespace Creating_Class

{
    class accept //Creating 1st. class
    {
        public string name;
        public void acceptdetails()
        {
            Console.Write("Enter your name:\t");
            name = Console.ReadLine();
        }
    }

    class print // Creating 2nd class

    {
        public void printdetails()
        {
            //Creating object of 1st. class
            accept a = new accept();
            //executing method of 1st class.
            a.acceptdetails();
            //Printing value of name variable
            Console.WriteLine("Your name is " + a.name);
        }
    }
    class Program //Creating 3rd class
    {
        static void Main(string[] args)
        {
            print p = new print();
            p.printdetails();
            Console.ReadLine();
        }
    }
}






  


output :













Saturday, September 28, 2013

C# Program to add Two numbers Csharp


C# Program to add two numbers Integers 
In this csharp tutorial we add two numbers
First we take two numbers and store them in variables
Then we show the result in output
For this we use console readline and console write line

Program :
using System;
 
namespace CsharpPrograms
{
    class Program
    {
        static void Main(string[] args)
        {
 
            int x;
            int y;
            int result;
            Console.Write("\n Enter the first number to be added: ");
            x=Convert.ToInt32(Console.ReadLine());
            Console.Write("\n Enter the second number to be added: ");
            y = Convert.ToInt32(Console.ReadLine());
            result = x + y;
            Console.Write("\n The sum of two numbers is: "+result);
            Console.ReadLine();
        }
    }
}
Output:

 

© 2013 1000TechTips. All rights resevered. Designed by Templateism

Back To Top