What is Cross Page Posting in ASP. NET? Example

Cross Page Posting means you are posting form data from one page to another page. 

By default Asp.net web form page ,button and other controls that cause post back submits current page back to itself.

Example 

TextBox txtStartDate = (TextBox) PreviousPage.FindControl("txtStartDate ");  
Share:

What is COALESCE in SQL Server? Example

COALESCE 

The SQL Coalesce and IsNull functions are used to handle NULL values. 

During the expression evaluation process the NULL values are replaced with the user-defined value.
 
The SQL Coalesce function evaluates the arguments in order and always returns first non-null value from the defined argument list.

Example

Select Id,COALESCE (Fullname,Middlename,Lastname) as Name from Employee





Share:

What is Generics in C#? Example.

Generics allow you to define the specification of the data type of programming elements in a class or a method, until it is actually used in the program. 

In other words, generics allow you to write a class or method that can work with any data type. 

Example 

class Program
    {
        static void Main(string[] args)
        {
            int [] ar={10,20,30,50,80,60};
            string [] ar1 = { "kul","amit","soham"};
            Student.Show(ar);
            Student.Show(ar1);
            Console.ReadLine();
        }
    }
    static class Student
    {
        public static void Show<T>(T [] ar)
        {
            for (int i = 0; i < ar.Length;i++ )
            {
                Console.WriteLine(ar[i]);
            }
        }
    }
Share:

How to find second highest number in Array in C#? Example.

Example

class Program

{

static void Main(string[] args)

{

int[] ar = {
10,
20,
50,
70,
40,
60,
90,
80
};

Array.Sort(ar);

Array.Reverse(ar);

Console.WriteLine("Second highest number : {0}", ar[1]);

Console.ReadLine();

}

}
Share:

What is the difference between STUFF and REPLACE in SQL Server? Example.

STUFF: Using the stuff function we delete a substring of a certain length of a string and replace it with a new string. 

REPLACE: As the function name replace indicates, the replace function replaces all occurrences of a specific string value with another string.

Example

SELECT STUFF('kul shresth',1,3,'nagar')
SELECT REPLACE('kulshresth kumar','kumar','nagar')
Share:

What is TPL in C#? Example.

Task Parallel Library (TPL) is a set of public types and APIs in the System.Threading and System.Threading.Tasks namespaces. 

The purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications.
 
Example

class Program
    {
        static void Main(string[] args)
        {
            //Action delegate 
            Task task1 = new Task(new Action(HelloConsole));

            //anonymous function 
            Task task2 = new Task(delegate
            {
                HelloConsole();
            });

            //lambda expression 
            Task task3 = new Task(() => HelloConsole());

            task1.Start();
            task2.Start();
            task3.Start();

            Console.WriteLine("Main method complete. Press any key to finish.");
            Console.ReadKey(); 
        }
        static void HelloConsole()
        {
            Console.WriteLine("Hello Task");
        } 
    }
Share:

What is Channel Factory C#? Example.

Channel Factory enables you to create a communication channel to the service without a proxy. 

Channel Factory that creates and manages the various types of channels which are used by a client to send a message to various configured service endpoints.
   
Example 

class FactoryPatternCurrent
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("enter your vehicles");
                string str = Console.ReadLine();
                Factory obj = new Factory();
                obj.CreateObj(str).Name();
                Console.ReadKey();
            }

        }
    }
    class Factory
    {
        public Vehicles CreateObj(string type)
        {
            Vehicles obj = null;
            switch (type)
            {
                case "car":
                    obj = new Car();
                    break;
                case "bike":
                    obj = new Bike();
                    break;
                default:
                    obj = new Car();
                    break;
            }
            return obj;
        }
    }
    interface Vehicles
    {
        void Name();
    }

    class Car : Vehicles
    {
        public void Name()
        {
            Console.WriteLine("WagonR");
        }
    }
    class Bike : Vehicles
    {
        public void Name()
        {
            Console.WriteLine("Activa");
        }
    }
Share:

What is difference between Singleton and Static class in C#? Example.

Singleton:- allows a class for which there is just one, persistent instance across the lifetime of an application. 

Static class :-allows only static methods and and you cannot pass static class as parameter. 

Singleton :-can implement interfaces, inherit from other classes and allow inheritance.

A- Singleton objects are stored in Heap, but static objects are stored in stack

B-We can clone (if the designer did not disallow it) the singleton object, but we can not clone the static class object.

C-Singleton classes follow the OOP (object oriented principles), static classes do not.

D-We can implement an interface with a Singleton class, but a class's static 
methods (Example:- a C# static class) cannot.


Important  :- Static Classes have only one object life, Hence we cannot create multiple objects of 
static classes but normal classes can be instantiated for creating many objects of the same class.

We use Static classes in scenarios in like creating a utilities class, implementing a singleton pattern.








Share:

What is use of Anonymous methods in C#? Example.

Anonymous methods provide a technique to pass a code block as a delegate parameter.

Anonymous methods are the methods without a name, just the body. You need not specify the return type in an anonymous method.

It is inferred from the return statement inside the method body.

Example 

public delegate void Print(int value);

static void Main(string[] args)
{
    Print print = delegate(int val) 
    {
        Console.WriteLine("Inside Anonymous method. Value: {0}", val);
    };

    print(100);
}
Share:

Tuesday, 10 September 2019

What is Cross Page Posting in ASP. NET? Example

Cross Page Posting means you are posting form data from one page to another page. 

By default Asp.net web form page ,button and other controls that cause post back submits current page back to itself.

Example 

TextBox txtStartDate = (TextBox) PreviousPage.FindControl("txtStartDate ");  

What is COALESCE in SQL Server? Example

COALESCE 

The SQL Coalesce and IsNull functions are used to handle NULL values. 

During the expression evaluation process the NULL values are replaced with the user-defined value.
 
The SQL Coalesce function evaluates the arguments in order and always returns first non-null value from the defined argument list.

Example

Select Id,COALESCE (Fullname,Middlename,Lastname) as Name from Employee





Saturday, 7 September 2019

What is Generics in C#? Example.

Generics allow you to define the specification of the data type of programming elements in a class or a method, until it is actually used in the program. 

In other words, generics allow you to write a class or method that can work with any data type. 

Example 

class Program
    {
        static void Main(string[] args)
        {
            int [] ar={10,20,30,50,80,60};
            string [] ar1 = { "kul","amit","soham"};
            Student.Show(ar);
            Student.Show(ar1);
            Console.ReadLine();
        }
    }
    static class Student
    {
        public static void Show<T>(T [] ar)
        {
            for (int i = 0; i < ar.Length;i++ )
            {
                Console.WriteLine(ar[i]);
            }
        }
    }

Thursday, 5 September 2019

How to find second highest number in Array in C#? Example.

Example

class Program

{

static void Main(string[] args)

{

int[] ar = {
10,
20,
50,
70,
40,
60,
90,
80
};

Array.Sort(ar);

Array.Reverse(ar);

Console.WriteLine("Second highest number : {0}", ar[1]);

Console.ReadLine();

}

}

What is the difference between STUFF and REPLACE in SQL Server? Example.

STUFF: Using the stuff function we delete a substring of a certain length of a string and replace it with a new string. 

REPLACE: As the function name replace indicates, the replace function replaces all occurrences of a specific string value with another string.

Example

SELECT STUFF('kul shresth',1,3,'nagar')
SELECT REPLACE('kulshresth kumar','kumar','nagar')

Wednesday, 4 September 2019

What is TPL in C#? Example.

Task Parallel Library (TPL) is a set of public types and APIs in the System.Threading and System.Threading.Tasks namespaces. 

The purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications.
 
Example

class Program
    {
        static void Main(string[] args)
        {
            //Action delegate 
            Task task1 = new Task(new Action(HelloConsole));

            //anonymous function 
            Task task2 = new Task(delegate
            {
                HelloConsole();
            });

            //lambda expression 
            Task task3 = new Task(() => HelloConsole());

            task1.Start();
            task2.Start();
            task3.Start();

            Console.WriteLine("Main method complete. Press any key to finish.");
            Console.ReadKey(); 
        }
        static void HelloConsole()
        {
            Console.WriteLine("Hello Task");
        } 
    }

What is Channel Factory C#? Example.

Channel Factory enables you to create a communication channel to the service without a proxy. 

Channel Factory that creates and manages the various types of channels which are used by a client to send a message to various configured service endpoints.
   
Example 

class FactoryPatternCurrent
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("enter your vehicles");
                string str = Console.ReadLine();
                Factory obj = new Factory();
                obj.CreateObj(str).Name();
                Console.ReadKey();
            }

        }
    }
    class Factory
    {
        public Vehicles CreateObj(string type)
        {
            Vehicles obj = null;
            switch (type)
            {
                case "car":
                    obj = new Car();
                    break;
                case "bike":
                    obj = new Bike();
                    break;
                default:
                    obj = new Car();
                    break;
            }
            return obj;
        }
    }
    interface Vehicles
    {
        void Name();
    }

    class Car : Vehicles
    {
        public void Name()
        {
            Console.WriteLine("WagonR");
        }
    }
    class Bike : Vehicles
    {
        public void Name()
        {
            Console.WriteLine("Activa");
        }
    }

What is difference between Singleton and Static class in C#? Example.

Singleton:- allows a class for which there is just one, persistent instance across the lifetime of an application. 

Static class :-allows only static methods and and you cannot pass static class as parameter. 

Singleton :-can implement interfaces, inherit from other classes and allow inheritance.

A- Singleton objects are stored in Heap, but static objects are stored in stack

B-We can clone (if the designer did not disallow it) the singleton object, but we can not clone the static class object.

C-Singleton classes follow the OOP (object oriented principles), static classes do not.

D-We can implement an interface with a Singleton class, but a class's static 
methods (Example:- a C# static class) cannot.


Important  :- Static Classes have only one object life, Hence we cannot create multiple objects of 
static classes but normal classes can be instantiated for creating many objects of the same class.

We use Static classes in scenarios in like creating a utilities class, implementing a singleton pattern.








Tuesday, 3 September 2019

What is use of Anonymous methods in C#? Example.

Anonymous methods provide a technique to pass a code block as a delegate parameter.

Anonymous methods are the methods without a name, just the body. You need not specify the return type in an anonymous method.

It is inferred from the return statement inside the method body.

Example 

public delegate void Print(int value);

static void Main(string[] args)
{
    Print print = delegate(int val) 
    {
        Console.WriteLine("Inside Anonymous method. Value: {0}", val);
    };

    print(100);
}

Popular

Total Pageviews

Archive