Sunday, 13 May 2018

Enumeration in C# and its practical use





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication13

{

    class Program

    {

        public enum gender {Male,Female }

        static void Main(string[] args)

        {l1:

            Console.WriteLine("Press 0 for Male");

            Console.WriteLine("Press 1 for Female");

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

            if (v==0)

            {

                Console.WriteLine("you have seleced "+gender.Male);

            }

            else if (v==1)

            {

                   Console.WriteLine("you have seleced "+gender.Female);

            }

            else

            {

                Console.ForegroundColor = System.ConsoleColor.Red;

                Console.WriteLine("Wrong selection .....");

                Console.ForegroundColor = System.ConsoleColor.White;



            }

            goto l1;

            Console.ReadLine();



        }

    }

}


Wednesday, 9 May 2018

Default and parameterized Constructor in C#





main class :

using ConsoleApplication11.Model;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication11

{

    class Program

    {

        static void Main(string[] args)

        {

            Employee emp = new Employee();

            emp.id = 1;

            emp.name = "ali";

            emp.salary = 50000;

            emp.showdata();

            Employee emp1 = new Employee(2, "ahmed", 60000);



            emp1.showdata();

            

            





        }

    }



}


Employee class: 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication11.Model
{
    class Employee
    {
        public int id;
        public string name;
        public float salary;
        public Employee() //default constructor..............
        {
            Console.WriteLine("Default Constructor is called");
        }

        public Employee(int id,string name,float salary) //default constructor..............
        {
            this.id = id;
            this.name = name;
            this.salary = salary;
            Console.WriteLine("Parametrized Constructor is called");
        }


        public void showdata()
        {
            Console.ForegroundColor = System.ConsoleColor.Cyan;
            Console.BackgroundColor = System.ConsoleColor.Red;
            Console.WriteLine("ID="+id);
            Console.WriteLine("Name = "+name );
            Console.WriteLine("Salary= "+salary);

        }

    }
}

Class and object in C# with real world Example





main class



using ConsoleApplication10.Model;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication10

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("How many Student you want to Add in Record: ");

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

            Student[] s = new Student[n];

            int id;

            string name;

            for (int i = 0; i < s.Length; i++)

            {

                id = i + 1;

                Console.WriteLine("Enter the name of student: ");

                name = Console.ReadLine();

                s[i] = new Student();

                s[i].insert(name, id);





            }



            foreach (Student item in s)

            {

                item.showRecord();

            }



            Console.ReadLine();

           

        }

    }

}

Student class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication10.Model
{
    class Student
    {
        public int id;
        public string name;
        public  Student()
        {

        }
        public void insert(string n,int id)
        {
            this.id = id;
            this.name = n;
        }
        public void showRecord()
        {
            Console.ForegroundColor = System.ConsoleColor.Green;
            Console.WriteLine("id : " + id);
            Console.WriteLine("Name : "+name);
            Console.ForegroundColor = System.ConsoleColor.White;

        }

    }
}

Tuesday, 8 May 2018

Params keyword in Array C#

\\using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication9

{

    class Program

    {



        public void show(params int []a)

        {

            for (int i = 0; i < a.Length; i++)

            {

                Console.WriteLine(a[i]);

            }



        }



        public void showobjects(params object[]a )

        {

            foreach (var item in a)

            {

                Console.WriteLine(item);

            }



        }

        static void Main(string[] args)

        {



            Program p = new Program();

           // p.show(1, 2, 3, 4,7);

            p.showobjects("ali", 1, "salman", 'c', 3.142);

            Console.ReadLine();

        }

    }

}


Monday, 7 May 2018

Learn C language Part -41 Type Casting in C language





#include <stdio.h>

#include <conio.h>



main()

{



float a=(float) 9/2;

float x=3.142;

int y=x;

printf("%d",y);

//printf("%f",a);



}

jagged Array in C#







using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication8

{

    class Program

    {

        static void Main(string[] args)

        {

            int [][]jagged=new int[3][];

            jagged[0]=new int[]{11,22,33,44,55,66};

            jagged[1] = new int[] { 12, 24, 36, 48 };

            jagged[2] = new int[] { 13, 26, 39 };





            for (int i = 0; i < jagged.Length ; i++)

            {



                for (int j = 0; j < jagged[i].Length; j++)

                {

                    Console.Write(jagged[i][j]+"\t");

                }

                Console.WriteLine();



            }

            Console.ReadLine();



        }

    }

}


Multi Dimensional Array in C# Matrices sum,Print









using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication6

{

    class Program

    {



        public void InputMatrix(ref int[,]a)

        {



            for (int i = 0; i < 3; i++) //row

            {



                for (int j = 0; j < 3; j++) //column

                {

                    Console.Write("Enter the Number at index X[{0},{1}] = ", i, j);

                    a[i, j] = int.Parse(Console.ReadLine());

                    Console.WriteLine();

                }



            }



        }









        public void printMatrix(int [,]a)

        {

            for (int i = 0; i < 3; i++) //row

            {



                for (int j = 0; j < 3; j++) //column

                {

                    Console.Write(a[i, j] + "\t");

                }



                Console.WriteLine();

            }



        }







        public int[,] sum(int[,] a, int[,]b)

        {

            int[,] c = new int[3, 3];



            for (int i = 0; i < 3; i++)

            {

                for (int j = 0; j < 3; j++)

                {



                    c[i, j] = a[i, j] + b[i, j];

                }





            }





            return c;

        }



        static void Main(string[] args)

        {

            Program p = new Program();

            int[,] x = new int[3, 3];

            int[,] y = new int[3, 3];

            int[,] z = new int[3, 3];

           

            p.InputMatrix(ref x);

            Console.WriteLine("\n---------------------Matrix A---------------\n");

            p.printMatrix(x);

            p.InputMatrix(ref y);



            Console.WriteLine("\n---------------------Matrix B---------------\n");

            p.printMatrix(y);



            z = p.sum(x,y);

            Console.WriteLine("\n---------------------Matrix C ---------------\n");

            p.printMatrix(z);

       



            Console.ReadLine();

         





        }

    }

}


Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...