Operator Overloading in C# Definition with example

Operator Overloading in c# Example 

In this article, I am going to discuss about operator overloading and it's example, Sometimes developers confused about it and they think operator overloading and function overloading is same but both are very different.

Definition of Operator overloading

The class allows creating a user to define the type or extract datatype. If we create a variable of that type is set to be an object but that object doesn't support all the operators it supports few operators like . and (Assignment operator), by using operator loading we can enhance the capabilities of an object to support the operator.

1. Operator overloading works on early binding approach.
2. We can't operator overload at that function which approaches decide at run-time.

Why we use operator overloading in c#
Used for to achieve object addition.

Steps for implementing operator overloading in c#
Here is some step that you need to follow while you are implementing operator overloading in c#.

1.The operator is a function is to be applied to support inbuilt operator to given an object
2.The opeartor function should be static(See Example).
3. This function always takes two parameters, can't have three parameters and must be public.
4.Note: We can't overload AND, OR, NOT like logical operator.
5. Operator function returns the object of containing class.

Example of Operator overloading

using System;
class office
    double salary;
    public office()
        salary = 0;
    public office(double sal)
        salary = sal;
    public void Display()
    public static office operator +(office o,office ob//it must be public static otherwise get compiler error
        office obj = new office();
        obj.salary = o.salary + ob.salary;
        return obj;

    static void Main()
        office a = new office(1212);
        office b = new office(7888);
        office accuntant = new office();
        accuntant = a + b;



Read More

Important Sql complex queries interview questions

Introduction: In this tutorial, I am going to explain the SQL complex queries which is asked in every interview questions. So let's start today's tutorial. So let's start SQL complex queries fo practice with answers.

Important Sql complex queries interview questions

1. To add new 
Alter table employee add gender varchar(5)

2.Drop a column
Alter table employee drop column gender

                       Some Ms. Sql commands with examples

3.Or operator  in SQL
SELECT * from employee where employeeid=or employeeid=1

4.IN function in SQL 
SELECT * from employee where employeeid in(2,3)

5. Find record Not in SQL table using  IN function
SELECT * from employee where employeeid not in (1,2)

6.Between function in SQL
SELECT * from employee where employeeid between 1 and 2

7.Select commands with order by clause
SELECT * from employee order by name 
SELECT * from employee order by name desc
SELECT * from employee order by name asc

8.Max Function
SELECT max(name) from employee
SELECT max(salary) from employee

9.Max Function
SELECT min(salary) from employee
SELECT min(name) from employee

10.Avg Function
SELECT AVG(salary) from emp

11.LEFT Function
SELECT LEFT('Manish',3)

12.RIGHT Function
SELECT RIGHT('Manish',3)

13.CHARINDEX Function- Is use to find the index(position) of any character

14.LEN Function- Is use to find the length of character
SELECT LEN('Manish')

Returns a datetime data type which contains current system data and time: 2018-09-24 09:51:36.568.

16.Use of AND Operator
SELECT * from employee where employeeid=2 and employeeid=5
SELECT * from employee where employeeid=2 and salary=600

17.Use of OR Operator
SELECT * from employee where employeeid=2 or employeeid=5
SELECT * from employee where employeeid=2 or salary=4000

18.Use of IN Operator
SELECT * from employee where employeeid in (2,5,8)

19.Use of Between Operator
SELECT * from employee where employeeid between 3 and 7

20.Use of WildCard Operator
SELECT * from employee where name not like 'a%'
SELECT * from employee where name like '%a'
SELECT * from employee where name like '%m%'
SELECT * from employee where name like '_a%'
SELECT * from employee where name like '%a_'
SELECT * from employee where name like '[a,b]%'
SELECT * from employee where name like '[a-p]%'

21.Use of SUBSTRING() Function

Read More

Easy Way:How to find 3rd higest salary in sql server

Find 3rd highest salary in SQL server

In this tutorial, I am going to show how we can find the 3rd highest salary in SQL Server. In below, the method I want to show you a very easy method so it will help to understand better. The method will take three step so please understand every step carefully.

create table EmployeeSalary 
   ID int identity primary key, 
   Name varchar(20), 
   Salary Decimal  

Insert into EmployeeSalary(Name,Salary)values('Ram',21000) 
Insert into EmployeeSalary(Name,Salary)values('Jhon',50000) 
Insert into EmployeeSalary(Name,Salary)values('Simant',40000) 
Insert into EmployeeSalary(Name,Salary)values('Tom',35000) 
Insert into EmployeeSalary(Name,Salary)values('Alia',25000) 
Insert into EmployeeSalary(Name,Salary)values('Mohan',22000) 
Insert into EmployeeSalary(Name,Salary)values('Raj',23000)

#Step 1:
In this query, I execute to show the record of  EmployeeSalary table

 * from EmployeeSalary

How to find 3rd higest salary in sql server
3rd higest salary in sql server

#Step 2: Now, Firstly find the top 3 salaries with descending order

Select  top 3 Name,Salary from EmployeeSalary order by salary desc

How to find 3rd higest salary in sql server
3rd higest salary

Let suppose the above record is a table, now we need to find a salary from current table record.

#Step 3: Find the top 1 record in ascending order from the current record 

select top 1 Name,Salary from (select  top 3 Name,Salary from EmployeeSalary order by salary desc) as T  order by salary asc

How to find 3rd higest salary in sql server
3rd highest salary 

Finally, we find the 3rd highest salary from SQL Server table


Read More