Wednesday, March 16, 2016

What is delegate in c#?



Delegate is a user defined data type, it is used to store the reference on method. C# delegate work same as c language pointer.

Use of the delegate: Use of the delegate is that when you have two or more methods with same name and same signature and call all the method with single object.

The example of the delegate is given below: 

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

namespace WindowsFormsApplication8
{
    public delegate int mydel(int x, int y);
   public class Class1
    {
        public int add(int a, int b)
        {
            return a + b;
        }

        public int sub(int a, int b)
        {
            return a - b;
        }
    }
}

.cs code 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Class1 obj = new Class1();
            mydel del = obj.add;
            int i = del(10, 20);
            MessageBox.Show(i.ToString());
            mydel del1 = obj.sub;
            int j = del1(20, 10);
            MessageBox.Show(j.ToString());
        }
    }
}
Output :
30
10




Types of delegate:
 
There are two types of delegate –
-Single cast delegates
-Multi cast delegates
Single cast Delegate – single cast delegate hold the address of single method like as explained in the above example.

Multicast Delegate - multicast delegate is used to hold the address of multiple methods, for this work we will use overloaded += operator and remove the address from delegate we use overloaded operator -=
Multicast Delegates will work for those methods which have return type only void.
The example of the Multicast delegates is given below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication9
{
    public delegate void mydel(int a, int b);
    public class Class1
    {
        public void add(int x, int y)
        {
            MessageBox.Show("addition value"+(x+y).ToString());
        }
        public void sub(int x, int y)
        {
            MessageBox.Show("subtraction value" + (x - y).ToString());
           
        }
        public void mul(int x, int y)
        {
            MessageBox.Show("multly value" + (x * y).ToString());
        }
    }
}


.cs code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Class1 obj = new Class1();
            mydel del = Class1.add;
            del += Class1.sub;
            del += Class1.mul;
            del(10, 5);



        }
    }
}

Output:
addition value : 15
subtraction value : 5
multiply value : 50



Tuesday, March 15, 2016

Case Sensitive in SQL Server

In this article, I am going to explain how to deal with case sensitive string in SQL query, On a general thought like you want to validate your login credential with SQL table by using  stored procedure, but by default match string and column value is not case sensitive in SQL.

Let's take an example,  firstly create a table for login and insert some value in it


create table U_Login
(
userid varchar(50) not null,
pwd varchar(50) not null
)
insert into U_Login (userid,pwd ) values ('sharad', 'sharad001')
insert into U_Login (userid,pwd ) values ('SHARAD', 'SHARAD001')

When you write given below query for login
select *  from U_Login  where userid='sharad' and pwd = 'sharad001'

Output

you can see above output image which shows both upper and lower case credentials.
But, we have just passed lower case credentials , so if you want to deal with case sensitive  information just write query as
SELECT *
FROM U_Login
WHERE userid = 'sharad' COLLATE SQL_Latin1_General_CP1_CS_AS
                AND pwd = 'sharad001' COLLATE SQL_Latin1_General_CP1_CS_AS


Now output

Friday, March 11, 2016

Dot Net interview question and answer for fresher



What is an application server?
An application server is a software engine that delivers applications to client computers. The name of the application server is IIS, IBM, Red Hat etc.

What is inheritance?
Inheritance is one of the fundamental object oriented programming language concept that allow the creation of hierarchical classifications.in C# programming the, a class that is inherited is called base class. In simple words the child class inherit variables, methods, properties and indexers of the parent class by using the “:” character. The main advantage inheritance is to re-usability of code.

How do you prevent a class from being inherited?
By making the class sealed

Can you use multiple inheritance in .NET?
We cannot use multiple inheritance in .NET directly it can be use by the interface

What is an Interface?
Interface is like a class but has no implementation it contains only declaration methods, properties and indexer .It is declared by the interface keywords in place of class.

What is abstract class in c#?
An abstract class is an incomplete class that cannot be instantiated, it only allow other class to inherit from it.an abstract method must be implemented in child class by using the override keyword.

What is structure in c#?
In C sharp Structure are the light weight classes and also value type, it contains fields, methods, constants, constructor, indexer.

Polymorphism in c # with example
Ability to take more than one form is called polymorphism. The polymorphism consist two words poly and morphism poly means “multiple” and morphism means “form”.

What is constructor in C#?
Constructor is special kinds of method which is automatically call when we create the instance or object of the class. It is also responsible for the object initialization and memory allocation of class.
Constructor name and class name should be same.
Constructor don’t return any value
We cannot inherited to the constructor
Constructor always public
Types of constructor
The types of Constructor are given below:
1. Default constructor
2. Parameterized constructor
3. Private constructor
4. Copy constructor
5. Static constructor

What is generic in C#?
Generic can be defined as <T> sign after the class name, by using the generic there is no need of boxing and unboxing. Generic also can be implemented with interfaces, delegates and methods.

What is Boxing/Unboxing?
Conversion of value type to reference type is called boxing and reference type to value type is called unboxing.

What is delegate?
Delegate is a user defined data type. It is used to store the reference of method.

What is Enum?
An Enum is a user defined value data type and also a group of related constant.

What is partial class?
Partial class is the class by which the class code is divided into two .cs file.

Why we use Generic?
By using the generic there is no need of boxing and unboxing.

What is the element of MSIL?
MSIT contains manifest, Meta data, assemble code

What is root name space?
System

What is super most class?
Object

You can create two default constructors
Yes, Static and Non Static

Does static constructor may be copy constructor
No

May the static constructor parameterized.
No Only Default.

What is CLS?
CLS is stand for common language specification, all the common set of rules which is necessary to follow to all the language is called CLS.

What of CTS?
CTS is stand for common type system the work of the CTS is to convert all language data type into the common data type.

What is business logic?
It is the functionality which handles the exchange of information between database and a user interface.

What is control?
A control is a component that provides UI (user interface) capabilities.

What is component?
Component is a group of related classes and methods.

What is globalization and localization?
Globalization is the process that the application support multiple culture and region, localization support a given culture and region.
What is overloading and overriding
Overloading means the class contains two or more methods with name and different signature, in overriding method name should be same and also same signature.

What is business logic?
Business logic is the functionality that handles the exchange of information between data base and user interface.

What is global assemble cache (GAC)?
GAC allows .Net applications to share libraries.GAC solve the problem of DLL Hell.

What is logging?
 Logging is the process of represent the information about the status of an application.
 
What is assembly?
Assembly is the primary unit of deployment of managed code it can be either DLL or .exe.

What is private assembly?
Private assemble is used by the single application.

What is shared assembly?
A shared assembly is used by the one or more application on a machine.

What is digital signature?
Digital signature is an electronic signature which is used to verify the identity of the person who is sending the message.

What is garbage collection?
Garbage collection is the process of remove the object which is not used for the longer time.


What is location of global assemble cache (GAC) on the system
C:\windows\assembly

What is difference between .tostring(), convert. Tostring()?
Difference both of them is that “convert” function handles Nulls while .tostrong() does not handle Null reference exception error.

What is collation?
Collation refers to set of rules that determine how the data is stored and compared

What is the difference between authorization and authentication?
Authorization is the process of allow or deny the resources to the particular user while the authentication is the process of identifying the credentials of user like username, password etc.
 





Wednesday, March 2, 2016

What is the difference between abstract class and interface in c#?

Abstract class


  • Abstract class not not support multiple inheritance
  • It contains constructor
  • An abstract class contains access modifier
  • Fast execution to find the actual method in the class
  • in abstract class fields and constraints have defined
  • An abstract class provides the complete code 
  •  Member of the abstract class can be static  
 Interface 


  • Interface support multiple inheritance
  • It does not contain constructor
  • an interface not not have any access modifier
  • Take more time to find the actual method in the class
  • fields can not be defined in the interface
  • An interface can not provide any code rather then the signature
  • member of the static class can not be static