Monday 14 May 2018

static keyword and static field in C#





MODEL CODE:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication15.Model

{

    class student

    {

        int id;

        string name;

        public static string batchcode="1708C1";



        public student(int id,string name)

        {

            this.id = id;

            this.name = name;

        }



        public void displayrecord()

        {

            Console.ForegroundColor = System.ConsoleColor.Red;



            Console.WriteLine("----------------------------------");

            Console.ForegroundColor = System.ConsoleColor.Green;



            Console.WriteLine("ID= " + id);

            Console.WriteLine("Name = "+name);

            Console.ForegroundColor = System.ConsoleColor.Cyan;



            Console.WriteLine("Batch Code: "+batchcode);

            Console.ForegroundColor = System.ConsoleColor.Red;

            Console.WriteLine("----------------------------------");



        }



    }

}

MAIN CLASS CODE:
 class Program
    {
        static void Main(string[] args)
        {
            student[] arr = new student[4];

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

             Console.WriteLine("ENTER THE NAME OF STUDENT: ");
             string n = Console.ReadLine();
             arr[i] = new student((i + 234), n);
               
            }


            foreach (student item in arr)
            {
                item.displayrecord();
            }

            Console.ReadLine();
        }
    }

This keyword in C#





 class Program

    {

        static void Main(string[] args)

        {

            employee EMP = new employee(12, 46000, "SALMAN");

            Console.ReadLine();

        }

    }



Model code:

    class employee

    {

        int id, salary;

        string name;

       public employee(int id,int salary,string name)

        {

            this.id = id;

            this.salary = salary;

            this.name = name;

            Console.WriteLine("ID: "+id);

            Console.WriteLine("NAME: "+name);

            Console.WriteLine("Salary: "+salary); 

       }

        

    }


This keyword in C#





 class Program

    {

        static void Main(string[] args)

        {

            employee EMP = new employee(12, 46000, "SALMAN");

            Console.ReadLine();

        }

    }



Model code:

    class employee

    {

        int id, salary;

        string name;

       public employee(int id,int salary,string name)

        {

            this.id = id;

            this.salary = salary;

            this.name = name;

            Console.WriteLine("ID: "+id);

            Console.WriteLine("NAME: "+name);

            Console.WriteLine("Salary: "+salary); 

       }

        

    }


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 ...