second day of c#

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace commonprogram

{

    class Program

    {

        static void Main(string[] args)

        {

            int age;

            Console.WriteLine("Enter Your Age");

            age=int.Parse(Console.ReadLine());

            if (age >= 18)

            {

                Console.WriteLine("you can vote");

            }

            else

            {

                Console.WriteLine("you cant vote");

    

            }

            Console.ReadKey();

 

 

        }

    }

}

 

 

 

 

Task – convert all old assignment into c#.

All marks>40 then calculate total and display grade (js).

 

Example for while loop

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace looping

{

    class Program

    {

        static void Main(string[] args)

        {

            int i = 1;

            while (i < 10)

            {

                Console.WriteLine(i);

                i = i + 1;

            }

            Console.ReadKey();

        }

    }

}

 

 

 

#Function:-

It is a small jobs programs.

#function separator= ()

# how to create a function in C#

Syntax:-

 Type function name()

{

 

}

 

 

By default all function is to be created void keywords.

Ex.

Void display()

{

 

}

 

# In C# all function is created before the main body.

 

 

·              To access any types of function in c# we need to use object.

·              Object is to be created inside the main body.

·              Syntax- 

Classname objname=new classname();

 

New is a keyword which means that it is memory allocation operators.

 

# how to access function

·              Aceess function using object

·              Syntax-

Objname.functionname();

;- this are called function calling operators

 

Ex for function-

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace function

{

    class Program

    { //create a function

        void display()

        { Console.WriteLine("welcome"); }

        static void Main(string[] args)

        {

            //create a object

            Program p1 = new Program();

            //access function

            p1.display();

            Console.ReadKey();

        

 

        }

    }

}

 

 

# all the input are created inside the main body.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace function

{

    class Program

    { //create a function

        void display(int a) // a is called receiver parameter

        { Console.WriteLine(a); }

        static void Main(string[] args)

        {

            //create a object

            Program p1 = new Program();

            int n;

            Console.WriteLine("enter any no.");

            n = int.Parse(Console.ReadLine());

            //access function

            p1.display(n);

            Console.ReadKey();

        

 

        }

    }

}

 

 

 

Assingement

1. else if any 3

1. Switch case any 2

2.Function with parameters any 4

Exclude local global

Comments

Popular posts from this blog

ViewState for state management

Store procedure Data Base handling (procedure_insert).

Database joining