Thursday 31 May 2018

Exception Handling in C# TRY CATCH STATEMENT









using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication35

{

    class Program

    {

        static void Main(string[] args)

        {

            int a;

            l1:

            Console.Write("Enter an integer number : ");

         

            try

            {

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

                Console.WriteLine("value of a =" + a);

            }

            catch (Exception ex)

            {

                Console.ForegroundColor = System.ConsoleColor.Red;

                Console.WriteLine("------------Error--------\n"+ex);

                Console.ForegroundColor = System.ConsoleColor.White;

                Console.WriteLine("Press any key to go back.....");

                Console.ReadLine();

                goto l1;

            }

           

            Console.ReadLine();



        }

    }

}


Link List in C# Generic class collection





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication34

{

    class Program

    {

        static void Main(string[] args)

        {

            var name = new LinkedList<string>();

            name.AddLast("Ali");

            name.AddLast("Ahmed");

            name.AddFirst("zahid");

            foreach (var item in name)

            {

                Console.WriteLine(item);

            }



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

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

            string s = Console.ReadLine();





            LinkedListNode<string> node = name.Find(s);

            name.AddBefore(node, "sami");

            name.AddAfter(node, "basit");

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

            foreach (var item in name)

            {

                Console.WriteLine(item);

            }



           

        }

    }

}


Queue Class in C# Generic Collection class





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication33

{

    class Program

    {

        static void Main(string[] args)

        {



            Queue<string> li = new Queue<string>();



            li.Enqueue("ali");

            li.Enqueue("ahmed");

            li.Enqueue("ahsan");

            li.Enqueue("asim");





            Console.WriteLine("top element : "+li.Peek());



            foreach (var item in li)

            {

                Console.WriteLine(item); 

            }



            Console.WriteLine("Press any key to dequeue...");

            Console.ReadLine();

           li.Dequeue();


            Console.WriteLine("top element : " + li.Peek());

            foreach (var item in li)

            {

                Console.WriteLine(item);

            }

            Console.ReadLine();

        }

    }

}


Wednesday 30 May 2018

Ceil ,Floor ,Square root , Power and Absolute function in C Language





#include <stdio.h>

#include <math.h>



main()

{



printf("Ceil function:   %f ",ceil(4.000001));

//4.1 =4.2=4.3=4.4 =4.0

//4.5 =4.5

//4.6 =4.7=4.8=4.9= 5.0



printf("\nfloor function : %f ",floor(4.000001));





printf("\nSquare root function : %f ",sqrt(4.0001));



printf("\nPower function : %f ",pow(2,3));



printf("\nAbsolute function : %d ",abs(2));







}

Tuesday 29 May 2018

Stack Class generic Collection in C#





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication32

{

    class Program

    {

        static void Main(string[] args)

        {





            Stack<string> s = new Stack<string>();

            s.Push("ALI");

            s.Push("Ahmed");

            s.Push("Basit");

            s.Push("zahid");

            s.Push("danish");

            s.Push("hasan");





            foreach (var item in s)

            {

                Console.WriteLine(item);

            }

            Console.WriteLine("Top Element is "+s.Peek());

            Console.WriteLine("press any key to pop element : ");

            Console.ReadKey();

            s.Pop();

            Console.WriteLine("Top Element is " + s.Peek());

            foreach (var item in s)

            {

                Console.WriteLine(item);

            }



            Console.ReadLine();

         



        }

    }

}


Sorted Set Class in C#





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication32

{

    class Program

    {

        static void Main(string[] args)

        {



            var x = new SortedSet<string>();

            x.Add("Zahid");

            x.Add("Ali");

            x.Add("Bilal");

            x.Add("Danish");

            x.Add("ali");



            foreach (var item in x)

            {

                Console.WriteLine(item);

            }



            Console.ReadLine();

         



        }

    }

}


Hash set Generic Class in C#





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication32

{

    class Program

    {

        static void Main(string[] args)

        {



            var x = new HashSet<string>();



            x.Add("ali");

            x.Add("AHMED");

            x.Add("ali"); //DUPLICATE......

            x.Add("ARIF");

            x.Add("ASIM");





            foreach (var item in x)

            {

                Console.WriteLine(item);

            }



            Console.ReadLine();





        }

    }

}


Monday 28 May 2018

convert upper to lower





#include <stdio.h>

#include <conio.h>

#include <string.h>





main()

{

char c[50],f;

printf("Enter the string: ");

gets(c);

int len=strlen(c),i=0,t;

char d[len];

while(i<len)

{

t=(int)c[i];

if(t>=65 && t<=90)

{

t=t+32;

}

f=(char)t;

d[i]=f;



i++;

}



puts(d);





}

Friday 25 May 2018

Check Palindrome using string function String copy , string Reverse, String







#include<stdio.h>

#include<conio.h>

#include <string.h>



main()

{



char s[50];

char d[50];

char t[50];



l1:

printf("Enter the string: ");

gets(s);



strcpy(t,s);





strcpy(d,strrev(s));



if(strcmp(t,d)==0)

{

printf("INPUT IS PALINDROME");



}

else

{

printf("INPUT IS NOT PALINDROME");





}

printf("\n\n\--------------------\n\n");

goto l1;



}




String Concat join function in C Language





#include<stdio.h>

#include<conio.h>

#include <string.h>



main()

{



char f[50];

char l[50];



printf("Enter the first name: ");

gets(f);



printf("\nEnter the Last name: ");

gets(l);



strcat(f,l);



puts(l);



}

Copy string from source to destination STRLEN ,STRCPY STRING FUNCTION IN C





#include<stdio.h>

#include<conio.h>

#include <string.h>



main()

{





char source[50];

printf("Enter the string: ");

gets(source);

int x=strlen(source);

char dest[x];

strcpy(dest,source);



printf("\nsource string is: %s ",source);

printf("\nDestination string is: %s ",dest);







}

Thursday 24 May 2018

List T in C# (GENERIC CLASSES)







class Employee

    {



        public int id { get; set; }

        public string name { get; set; }



    }





--------------------------------------------------------------------------



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication30

{

    class Program

    {

        static void Main(string[] args)

        {

            List<Employee> li = new List<Employee>();

            Console.WriteLine("How many records you want to add in list:");

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

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

            {

                Console.ForegroundColor = System.ConsoleColor.Yellow;

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

                Employee emp = new Employee();

                emp.name = Console.ReadLine();

                emp.id = i + 1;

                li.Add(emp);

                Console.ForegroundColor = System.ConsoleColor.Green;

                Console.WriteLine("1 RECORDS SUCCESSFULLY INSERTED IN LIST.......");

                Console.WriteLine("PRESS ANY KEY.....");

                Console.ReadLine();

                Console.Clear();



            }



            Console.WriteLine("PRESS ANY KEY.....");

            Console.ReadLine();

         

            foreach (var item in li)

            {

                Console.ForegroundColor = System.ConsoleColor.Red;

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

                Console.ForegroundColor = System.ConsoleColor.Cyan;

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

                Console.WriteLine("Name: " + item.name);

                Console.ForegroundColor = System.ConsoleColor.Red;

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

               



            }



            Console.ReadLine();

        }

    }

}


Collection Classes in C# Generic Classes







using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication29

{

    class Program

    {

        static void Main(string[] args)

        {

            string t;

            List<string> li = new List<string>();

            Console.WriteLine("How many names you want to add in list: ");

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

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

            {

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

                t = Console.ReadLine();

                li.Add(t);

                Console.ForegroundColor = System.ConsoleColor.Green;

                Console.WriteLine("Data successfully added in list.....");

                Console.ReadLine();

                Console.Clear();

                Console.ForegroundColor = System.ConsoleColor.White;

           

            }

            Console.ForegroundColor = System.ConsoleColor.Green;

           

            Console.WriteLine("Press any key to print all names");

            Console.ReadLine();



            foreach (var item in li)

            {

                Console.ForegroundColor = System.ConsoleColor.Yellow;

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

            }



            Console.ReadLine();

        }

    }

}


Serialization and Deserialization in C#





C# Serialization

string path = @"C:\Users\salman\Desktop\FILE\serial.doc";

         

            Student s = new Student(1, "Salman");

            FileStream stream = new FileStream(path, FileMode.OpenOrCreate);

            BinaryFormatter formater = new BinaryFormatter();

            formater.Serialize(stream, s);

            stream.Close();

            Console.ForegroundColor = System.ConsoleColor.Red;

            Console.WriteLine("File saved in "+path);

            Console.ReadLine();



------------------------------------------------------------------------------

C# Deserialization





string path = @"C:\Users\salman\Desktop\FILE\serial.doc";

 FileStream stream = new FileStream(path, FileMode.OpenOrCreate);

            BinaryFormatter formater = new BinaryFormatter();

            Student s = (Student)formater.Deserialize(stream);

            Console.ForegroundColor = System.ConsoleColor.Green;

            Console.WriteLine("Id :"+s.id);

            Console.WriteLine("Name :" + s.name);

            Console.ReadLine();
--------------------------------------------------------------

STUDENT CLASS:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication28
{   [Serializable]
    class Student
    {
        public int id;
        public string name;

        public Student(int id, string name)
        {
            this.id = id;
            this.name = name;

        }

    }
}

Sunday 20 May 2018

How to Create folder Directory in C#





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.IO;



namespace ConsoleApplication25

{

    class Program

    {

        static void Main(string[] args)

        {



            l1:

            Console.WriteLine("Enter the folder name :");

            string n = Console.ReadLine();

            DirectoryInfo DIR = new DirectoryInfo(@"C:\Users\salman\Desktop\FILE\"+n);





            try

            {



                if (DIR.Exists)

                {

                    Console.WriteLine("THIS FOLDER ALREADY EXIST......\nPress any key to go back");

                    Console.ReadLine();

                    Console.Clear();

                    goto l1;

                }

                else

                {

                    DIR.Create();

                    Console.Write("fOLDER CREATED.....");

                }





            }

            catch (Exception E)

            {

                Console.ForegroundColor = System.ConsoleColor.Red;

                Console.WriteLine("Folder couldnot be created due to " + E);

            }



            Console.WriteLine("Enter the folder that u want to delete.......");

            n = Console.ReadLine();

            new DirectoryInfo(@"C:\Users\salman\Desktop\FILE\" + n);

            DIR.Delete();

            Console.WriteLine("Folder deleted.....");

            Console.ReadLine();



        }

    }

}


Text Reader and Text Writer in C# File Read Write Operation







-------------------------------------------------------------------------------------------------------------

Text WRITER IN C#

-------------------------------------------------------------------------------------------------------------

         

 using (TextWriter wr=File.CreateText(@"C:\Users\salman\Desktop\FILE\textwriter.txt"))

            {



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

                {

                    wr.WriteLine((i+1)+"SALMAN MASOOD THE CONCEPT ACADEMY.....");

                }







            }

            Console.WriteLine("FILE CREATED SUCCESSFULLY....");


-------------------------------------------------------------------------------------------------------------

Text READER IN C#

-------------------------------------------------------------------------------------------------------------

  using (TextReader tr = File.OpenText(@"C:\Users\salman\Desktop\FILE\textwriter.txt"))

            {

                Console.WriteLine(tr.ReadToEnd());



            }

            Console.ReadLine();

Stream Writer and Stream Reader in C# File READ WIRTE OPERATIONS





-------------------------------------------------------------------------------------------------------------
FileStream Writer : Code
------------------------------------------------------------------------------------------------------------


 FileStream f = new FileStream(@"C:\Users\salman\Desktop\FILE\streamwriter.txt", FileMode.Open);

            StreamReader r = new StreamReader(f);

            string msg = r.ReadLine();

            Console.ForegroundColor = System.ConsoleColor.Red;



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

         

            Console.ForegroundColor = System.ConsoleColor.Green;





            Console.WriteLine(msg);



            Console.ForegroundColor = System.ConsoleColor.Red;



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

            f.Close();

         

            Console.ReadLine();

-------------------------------------------------------------------------------------------------------------
FileStream Reader : Code
------------------------------------------------------------------------------------------------------------

FileStream f = new FileStream(@"C:\Users\salman\Desktop\FILE\streamwriter.txt", FileMode.Create);
            StreamWriter s = new StreamWriter(f);
            Console.WriteLine("Enter your text: ");
            string msg = Console.ReadLine();

            s.Write(msg);
            s.Close();
            f.Close();
            Console.WriteLine("File created successfully.............");
            Console.ReadLine();



Thursday 17 May 2018

File Stream in C# (How to read /write a text file in C#)





using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication21

{

    class Program

    {

        static void Main(string[] args)

        {

            FileStream F = new FileStream(@"C:\Users\salman\Desktop\FILE\salman.txt",FileMode.OpenOrCreate);

            Console.WriteLine("Enter the text :");

            string s = Console.ReadLine();

            byte[] ascii = Encoding.ASCII.GetBytes(s);

            foreach (byte item in ascii)

            {

                F.WriteByte(item);

            }



            Console.WriteLine("Data successfully written in file named as salman.txt");



            F.Close();





            Console.WriteLine("Press any key to read the same file............");

            Console.ReadKey();

            FileStream F2 = new FileStream(@"C:\Users\salman\Desktop\FILE\salman.txt", FileMode.OpenOrCreate);

            Console.ForegroundColor = System.ConsoleColor.Green;

            int i = 0;

            while ((i=F2.ReadByte())!=-1)

            {

                Console.Write((char)i);

            }

            Console.ReadKey();

            F2.Close();

       



        }

    }

}


Properties in C#







using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication20

{

    class Program

    {

        static void Main(string[] args)

        {

            EMPLOYEE EMP = new EMPLOYEE();

            Console.WriteLine("Enter the ID: ");

            EMP.ID = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter the name ");

            EMP.NAME = Console.ReadLine();

            Console.WriteLine("Enter the salary ");

            EMP.SALARY = float.Parse(Console.ReadLine());



            EMP.display();

     

        }

    }

}
-------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication20
{
    class EMPLOYEE
    {
        public int ID { get; set; }
        public string NAME { get; set; }

        public float SALARY { get; set; }
   
    public void display()
        {

            Console.WriteLine("ID: "+ID);
            Console.WriteLine("Name "+NAME);
            Console.WriteLine("Salary: "+SALARY);

        }
   
    }
}


struct in C#



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication19

{

    class Program

    {

        static void Main(string[] args)

        {



            Rectangle r = new Rectangle(4,3);

            r.displayarea();

            Console.ReadLine();

        }

    }



    public struct Rectangle

    {

        int w, h;

        public Rectangle(int h, int w)

        {

            this.h = h;

            this.w = w;

        }



        public void displayarea()

        {



            Console.WriteLine("Area of Rectangle is "+(w*h));

        }



    }

}


Wednesday 16 May 2018

Static Constructor in C#





STUDENT CLASS:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication18.Model

{

    class student

    {



        int id;

        string name;

        static string collegename;

        public student(int id,string name)

        {

            this.id = id;

            this.name = name;

        }

        static student()

        {

            collegename = "Govt Dehli College";

        }



        public void display()

        {

           

            Console.ForegroundColor = System.ConsoleColor.Green;

            Console.WriteLine("************************************");

            Console.ForegroundColor = System.ConsoleColor.Magenta;

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

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

            Console.WriteLine("College: "+collegename);



            Console.ForegroundColor = System.ConsoleColor.Green;

            Console.WriteLine("************************************");



        }

    }

}

MAIN CLASS:
using ConsoleApplication18.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication18
{
    class Program
    {
        static void Main(string[] args)
        {
            student[] s = new student[]
            {
                new student(123,"salman"),
                 new student(124,"ali"),
                  new student(125,"sana"), 
                  new student(126,"kashif"),
            };

            foreach (student item in s)
            {
                item.display();
            }


        }
    }
}


Tuesday 15 May 2018

Static Class and Method in C#



Mathematics Class: 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication16.Model

{

   static class Mathematics

    {

       public static float pi = 3.124f;

   public static double areaofcircle(float r)

   {

       return pi * Math.Pow(r, 2);

       



   }





   public static double circumferencecircle(float r)

   {

       return 2 * pi * r;





   }







   }



}

Main class:
using ConsoleApplication16.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {

            float r;
            l1:
            Console.WriteLine("Enter the radius of circle:");
            r = float.Parse(Console.ReadLine());
            if (r<0)
            {
                Console.ForegroundColor = System.ConsoleColor.Red;
                Console.WriteLine("Radius cannot be negative.....");
             Console.ForegroundColor=System.ConsoleColor.White;
            }
            else
            {
                Console.ForegroundColor = System.ConsoleColor.Green;
                Console.WriteLine("Area of Circle is " + Mathematics.areaofcircle(r));
                Console.ForegroundColor = System.ConsoleColor.Magenta;
                Console.WriteLine("Circumference  of Circle is " + Mathematics.circumferencecircle(r));
                Console.ForegroundColor = System.ConsoleColor.White;
            }
            Console.WriteLine("Press any key to continue....");
            Console.ReadKey();
            Console.Clear();
            goto l1;
        }
    }
}


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); 

       }

        

    }


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();

         





        }

    }

}


Friday 4 May 2018

How to Find Largest and Smallest Number From Array in C#



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace array

{

    class Program

    {



        public int sum( int []x)

        {

            int sum = 0;

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

            {

                sum = sum + x[i];

            }



            return sum;

        }





        public int findmax(int []x)

        {

            int max=x[0];



            for (int i = 1; i < x.Length; i++)

            {

                if (max<=x[i])

                {

                    max = x[i];

                }

            }



            return max;

        }



        public int findmin(int[] x)

        {

            int min = x[0];



            for (int i = 1; i < x.Length; i++)

            {

                if (min >= x[i])

                {

                    min = x[i];

                }

            }



            return min;

        }



        static void Main(string[] args)

        {



            int[] a = new int[] { 10, 20, 30,50,100 };

            Program p = new Program();

          int v = p.sum(a);

          Console.WriteLine("sum of array is : "+v);

          Console.WriteLine("max number is "+p.findmax(a));

          Console.WriteLine("min number is " + p.findmin(a));









            Console.ReadLine();

        }

    }

}


Introduction to Array in C#



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace array

{

    class Program

    {

        static void Main(string[] args)

        {

            int[] a = new int[3]; //decalaration......

            int[]b = new int[3]{11,32,10,}; //array initialization

            int[] c = new int[] { 32, 43, 65, 76, 34, 32,65 }; //array initialization

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



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

            {

                Console.WriteLine(a[i]);

            }

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



            int  x = 0;

            while (x<b.Length)

            {

                Console.WriteLine(b[x]);

                x++;

            }

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

            foreach (int item in c)

            {

                Console.WriteLine(item);   

            }











            Console.ReadLine();

        }

    }

}


Wednesday 2 May 2018

Out parameter Function in C#









using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication5

{

    class Program

    {

        public float calavg(int a,int b,int c,out int sum)

        {

            sum = a + b + c;

            return sum / 3;

       

        }





        public float calavg2(int a, int b, int c, ref int sum)

        {

            sum = a + b + c;

            return sum / 3;



        }





        static void Main(string[] args)

        {

            Program p=new Program();

            int d1=54, d2=78, d3=100,s=0;

            float avg;



           /* avg = p.calavg(d1, d2, d3,out s);

            Console.WriteLine("total score is "+s);

            Console.WriteLine("avg score is "+avg);

            */



         avg=   p.calavg2(d1, d2, d3, ref s);



            Console.WriteLine("total score is " + s);

            Console.WriteLine("avg score is " + avg);

            Console.ReadLine();



        }

    }

}


Difference between Call by value and Call by Reference





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication4

{

    class Program

    {

        public void sum(float a, float b)

        {

           float x=a + b;

           Console.WriteLine(x);

        }



        public int changevalue(int x)

        {

            x = x * x;

            return x;

        }

        public int changereference(ref int x)

        {

            x = x + x;

            return x;

        }

       

        static void Main(string[] args)

        {

            Program p = new Program();

            int a = 5;

            Console.ForegroundColor = System.ConsoleColor.Red;

            Console.WriteLine("call by value ..............................");

            Console.ForegroundColor = System.ConsoleColor.White;

            Console.WriteLine("value from function " + p.changevalue(a));

            Console.WriteLine("actual value of a = "+a);

            Console.ForegroundColor = System.ConsoleColor.Red;

            Console.WriteLine("call by Reference ..............................");

            Console.ForegroundColor = System.ConsoleColor.White;

            Console.WriteLine("output from function : " + p.changereference(ref a));

            Console.WriteLine("actual value of a = " + a);

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