Posts

Showing posts with the label c#

59.SortedList in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace sortedlist {     class Program     {         static void Main(string[] args)         {             SortedList s1 = new SortedList();             s1.Add("key1", 50);             s1.Add("key2", 60);             s1.Add("key3", 70);             s1.Add("key4", 80);             s1.Add("key5", 90);             foreach (DictionaryEntry sname in s1)             {                 Console.WriteLine("Key : " + sname.Key + "  And  Values : " + sname.Value);             } ...

58. HashTable In C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace HashTable {     class Program     {         static void Main(string[] args)         {             Hashtable h1 = new Hashtable();             h1.Add("s1", "Milan");             h1.Add("s2", "Bakotra");             h1.Add("s3", "Divi");             h1.Add("s4", "Divu");             h1.Add("s5", "Vidhi");             foreach (DictionaryEntry sname in h1)             {                 Console.WriteLine("Key : " + sname.Key + "  And Value : " + sname.Value);           ...

57.ArrayList in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace arraylist {     class Program     {         static void Main(string[] args)         {             ArrayList arr1 = new ArrayList();             arr1.Add("Milan");             arr1.Add("Krunal");             arr1.Add("Divya");             arr1.Add("Riya");             arr1.Add("Divi");             foreach (String val in arr1)             {                 Console.WriteLine(val);             }             Stack s1 = new Stack();   ...

56.Queue Class Example in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace queue {     class Program     {         static void Main(string[] args)         {             Queue q1 = new Queue();             q1.Enqueue(5);             q1.Enqueue(15);             q1.Enqueue(25);             q1.Enqueue(35);             q1.Enqueue(45);             foreach (int var in q1)             {                 Console.WriteLine(var);             }             Console.WriteLine("==== After Dequeue ====");       ...

55. Stack class in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace stack_class {     class Program     {         static void Main(string[] args)         {             Stack s1 = new Stack();             s1.Push(5);             s1.Push(15);             s1.Push(25);             s1.Push(35);             s1.Push(45);             foreach (int val in s1)             {                 Console.WriteLine(val);             }                          s1.Pop();       ...

54.multicasting delegate in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace multicasting_delegate {     public delegate void Delegate_op(double a, double b);     class Program     {         static void mul(double x, double y)         {             Console.WriteLine("Multiplication : " + x * y);         }         static void add(double x, double y)         {             Console.WriteLine("Addition : " + (x + y));         }         static void div(double x, double y)         {             Console.WriteLine("Division : " + x / y);         }         static void sub(double x, double y)         {   ...

53.Delegate as class data member

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace delegate_as_class_data_member {     public delegate void Delgate_op(string msg);     class delegate_class     {         public static void wlc(string msg)         {             Console.WriteLine("Welcome " + msg);         }         public static void Bye(string msg)         {             Console.WriteLine("Bye " + msg);         }     }     class Program     {         static void Main(string[] args)         {             Delgate_op obj = new Delgate_op(delegate_class.wlc);             obj("Milan");       ...

52.Delegate without argument without return value in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace delegate2 {     public delegate void Delegate();     class Program     {         static void hi()         { Console.WriteLine("HI... "); }         static void welcome()         { Console.WriteLine("Welcome to The C# Programming"); }         static void Main(string[] args)         {             Delegate obj_del = new Delegate(hi);             obj_del();             obj_del = welcome;             obj_del();             Console.Read();         }     } } OUTPUT: HI... Welcome to The C# Programming

51.Delegate with argument with return value in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace simple_delegate {     public delegate double Demo(double a, double b);      class Program     {         static double mul(double x, double y)         { return x * y;  }         static double add(double x, double y)         { return x + y; }         static void Main(string[] args)         {             Demo obj_del1 = new Demo(mul);             Demo obj_del2 = new Demo(add);             Console.Write("Enter First Value : ");             double d1 = Convert.ToDouble(Console.ReadLine());             Console.Write("Enter Second Value : ");     ...

50. Pointer to Array in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace poiter_to_arrray_fixed {     class Program     {         public static unsafe void printall(int* ptr)         {             for (int i = 0; i < 10; i++)             {                 Console.WriteLine(*(ptr + i));             }         }         static unsafe void Main(string[] args)         {             int[] arr = new int[10];             for (int count = 0; count < 10; count++)             {                 arr[count] = count * count;           ...

49.swap_value_uisng_pointer

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace swap_value_uisng_pointer {     class Program     {         unsafe public static void swap(int* x, int* y)         {             int temp;             temp = *x;             *x = *y;             *y = temp;         }         static unsafe void Main(string[] args)         {             int a = 33;             int b = 22;             Console.WriteLine("Before Swamp() : a={0}, b={1}", a, b);             swap(&a, &b);             Console.WriteLine("After Swap() : a={0}, b=...

48.pointer in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace pointer {     class Program     {         unsafe static void Main(string[] args)         {             int a = 10;             int b = 30;             int* ptr = &a;             int* ptr1 = &b;             Console.WriteLine("A = {0}  *ptr = {1}  (int)ptr = {2}",x, *ptr, (int)ptr);             Console.WriteLine("A = {0}  *ptr1 = {1}  (int)ptr1 = {2}", x, *ptr1, (int)ptr1);                Console.Read();         }     } } OUTPUT: A = 10  *ptr = 10  (int)ptr = 111209320 A = 30  *ptr1 = 30  (int)ptr1 = 11...

47.Indexer in C#

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace indexerexample {     class clsindexer     {         private string[] range = new string[10];         public string this[int indexrange]         {             get { return range[indexrange]; }             set { range[indexrange] = value; }         }     }     class Program     {         static void Main(string[] args)         {             clsindexer obj = new clsindexer();             obj[0] = "Raj";             obj[1] = "Rahul";             obj[2] = "Deep";             obj[3] = "Faiz...

46.Nasted Namespace

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace nestednamepsaceexample {     namespace FYBCA     {         namespace SYBCA         {             class SYBCA_Class             {                 public static void hello()                 {                     Console.WriteLine("Hello");                     Console.Read();                 }             }         }     }     class Program     {         static void Main(string[] args)         {   ...

45. multiple_namespace

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace multiple_namespace {     namespace namespace1     {         class A         {             public void print()             {                 Console.WriteLine("This is First Namespace");             }         }     }     namespace namespace2     {         class A         {             public void print2()             {                 Console.WriteLine("This is second Namespace");             }         }     }     cl...

44.Simple Namespace

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace simple_namespace {     namespace first_namespace     {         class demo         {             public void print()             {                 Console.WriteLine("This is first simple namespace");             }         }     }     class Program     {         static void Main(string[] args)         {             first_namespace.demo obj = new first_namespace.demo();             obj.print();             Console.Read();         }     } } OUTPUT: This is first simple...

43.multilevel inheritance using interface

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace multiple_interface {     interface emp_info     {         int EID { get; set; }         string ENAME { get; set; }         DateTime DOJ { get; set; }         int exprince();     }     interface dpt_nm     {         string DPT_NAME { get; set; }     }     class child1 : emp_info, dpt_nm     {         public int eid;         public string nm, dp;         public DateTime dt;         public int EID         {             get { return eid; }             set { eid = value; }         }       ...

42.static_class and _method

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace static_class_method.cs {     static class demo     {         public static void msg()         {             Console.WriteLine("This is static method of staitc class demo");         }     }     class Program     {         static void Main(string[] args)         {             demo.msg();             Console.Read();         }     } } OUTPUT: This is static method of staitc class demo

40.sealed method, it cannot be overridden.

 /*  If you create a sealed class, it cannot be derived. If you create a sealed method, it cannot be overridden. Local variables can't be sealed. The sealed method in C# cannot be overridden further. It must be used with override keyword in method. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sealed_method.cs {     class Base     {         public virtual string display()         {             return "Base class method";         }     }     class Derived : Base     {         public sealed override string display()         {             return "sealed mehtod of Derived class";         }     }     class Program     {       ...

41. Partial class : class is divide

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace partial_class.cs {     partial class BCA     {         public void hi()         {             Console.WriteLine("HI...");         }     }     partial class BCA     {         public void hello()         {             Console.WriteLine("Hello...");         }     }     class Program     {         static void Main(string[] args)         {             BCA obj = new BCA();             obj.hi();             obj.hello();             Console.Read(); ...