OOPS Logical questions in c#,Interview Question

Introduction:- Today I am here with OOPS Logical questions in c#,which is mostly ask in every interview question. It will help you to crack C# OOPS interview.

OOPS Logical questions in c#,INTERVIEW QUESTION
OOPS Logical questions in c#

Q1:What is object ?
An object is a instance of class and also it is reference pointer of a class. It allocated the memory to access the member of class. If we want to access the class member we need to create object of that particular class.

  Syntax for Object
  ClassName objectname=new ClassName();
  e.g Employee emp=new Employee();

In the above syntax object emp is a reference pointer for the Employee class.

Q.2: What is naming convention?
Naming convention is a set of or a business logic rule by which we chose the character sequence to be used for function,class,textbox or any other entities in our source code so that later on we can easily  remember these sequence.

Q.3:Can we create class name with number?
No,We can't start class name with number only we can use number in between i.e.

Public class Emp123


Q.4:Can we use special character to create the class?
Yes only underScore (_)

Q.5:By default class follow which access modifier?

Q.6:Types of Access specifier/modifier ?
There are 5 type of access modifier.
5.Protected Internal

Q.7: Can we create class as private/protected/protected internal ?
No,By default class is Internal and you can mark class as Public only.

Q.8: By default class members are, means access modifier?

Q.9: Difference b/w public ,private and internal access modifier?
Difference Public/private/Internal/Protected/Protected internal
1.Public:                 Accessible in any project, but you have to add the reference
2.Private:                Member can be accessed in same class only.
3.Internal:               Same Project.same Library,same assembly only.
4.Protected:            Only available in child class.
5.Procted Internal:   It behaves like procted + internal

Q.10: Diffrence between protected and protected internal ?

Q.11:Can we mark method as a sealed.

Q.12:Is it possible to overload static constructor
No its not.

Q.13:Why object of abstract class can’t be instantiate
An abstract class has a protected constructor (by default) allowing derived types to initialize it.
An abstract type is defined largely as one that can't be created. You can create subtypes of it, but not of that type itself. The CLI will not let you do this.

Q.14:Does Enum Supports Inharitence
Enums do not supports inheritance since they are value type and therefor are sealed.Enum is like struct.it is having the nature of sealed class.so it doesn't support inheritance.

Q.15:Where does the value of variables in structure get stored in memory ?
Its store on Stack because Structure are value type.

Q.16:Can we use virtual keyword with functions in interface
This is no need to use virtual keyword with functions of interface as it is by default made to override.  

Q.17:Is it possible to change access specifier of members of interface.
No,We cannot make change in method of interface just why because interface is publicly exposed for construction,so interface methods are public by default.
If you want to change access specifier of members may you have to go for abstract class instead of interface.

Read More

Diffrence between protected and protected internal in c#

In this tutorial we will talk about actual diffrence between protected and protected internal.

Diffrence between protected and protected internal


1.In case of protected access is limited to the containing class or types derived from the containing class.

2.This can be accessed within same project as well as outside(by inheritance)   of the project,only access in child class(by inheritance) simply call the   method.

3.The protected member can not be accessed by creating the object of class.

Protected Internal:

1.Access is limited to the current assembly or type derive from the containing class.

2.This can also be accessed within same as well as outside the project but also can be accessed as internal.

3.Protected internal member can be accessed by creating the object in same project only.

4.It behaves like Protected+Internal.

Read More

How to convert vertical data to horizontal in sql

Conversion of vertical data to horizontal in sql: Today I am going to show you how to convert vertical data to horizontal in ms sql. Here we have multiple ways by which we can convert vertical data to horizontal in sql. Here are some simple transformation of data from vertical to horizontal. 

Table structure

 display data vertically in sql
Insert Some data in table and select it

How to convert vertical data to horizontal in sql

Method1: to convert vertical data to horizontal in sql
Select * from PartsItem

Declare @ProductSKU varchar(MAX)='  '
select @ProductSKU= @ProductSKU+ ISNULL
(ProductSKU+', ' ' ') from PartsItem Select @ProductSKU as ProductSKUCode

 display data vertically in sql

Method2: to transformation of vertical data to horizontal in sql
It will show the record is in form of XML

Select ProductSKU + ' , '  from PartsItem for xml path ('  ')

How to convert vertical data to horizontal in sql

Read More

[Solved] How to add watermark in textbox in asp.net using ajax

Introduction : Today I am going to show you how to add water in textbox in asp.net webform using ajax.This is very simple to implement watermark in asp.net textbox. Let's see how we can done this.


1.Add one asp.net webform.
2.Register the AjexToolKit assembley at the top of webform
3.Add the script in <head> section.
4.Add ToolKitScriptManager.
5.Take one textbox. 

Let's have a look

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="watermark-textbox.aspx.cs" Inherits="watermark-textbox" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>how to add watermark in textbox in asp.net using ajax</title>
    <script type="text/javascript">
        function WaterMark(txtName, event) {
            var defaultText = "Enter Username Here";
            // Condition to check textbox length and event type
            if (txtName.value.length == 0 & event.type == "blur") {
                //if condition true then setting text color and default text in textbox
                txtName.style.color = "Gray";
                txtName.value = defaultText;
            // Condition to check textbox value and event type
            if (txtName.value == defaultText & event.type == "focus") {
                txtName.style.color = "black";
                txtName.value = "";
    <form id="form1" runat="server">
        <ajax:ToolkitScriptManager ID="k1" runat="server"></ajax:ToolkitScriptManager>
        <asp:TextBox ID="txtUserName" runat="server" Text="Enter Username Here" ForeColor="Gray" onblur="WaterMark(this, event);" onfocus="WaterMark(this, event);" />


Read More

Function in SQL and use of SQL function at project level

Function in MS SQL Server,Use of function

Introduction:Function is used to perform the set of task or we can write multiple queries in a function and we can call n-number of times , So function gives me reusability of queries.

Why we create(make) function in MS SQL Server

Reusability:-Once we make a function we can call many times from asp.net application or any other application.

Actual Use of function at project level:

1.Function can return single value, it can’t return multiple value due to “returns” keyword.
2.Function can call another function.
3.At the project level the actual use of function is to perform the computational or calculation like to findout the no. of leave taken by the employee, sum of employee salary etc.
4.By the function we can fetch a record or search a record.
5.By the function we can’t perform DML operation(like insert,delete,update). This is the reason I wann go for Store procedure.


When we make a function it will go within DBO (DataBase Owner), became if we want to call the function we must include dbo.function name let’s see.

Create function [SearchName](@code int)
returns varchar(20)
       return 'Deepak'

select dbo.SearchName(107) 

So, how many ways we can call function in Sql: There are following ways we can call function in MS SQL Server.

1.select dbo.SearchName(107)
2.print dbo.SearchName(107)
3.Declare @detail varchar(50)
SET @detail=dbo.SearchName(107)
print @detail

Function in SQL and use of SQL function at project level

Type of function in MS SQL Server:

If you go under programmability section,then you can see function is 3-Type

1.System Function
2.Table-Valued Function
3.Scaler-Valued Function

Function in SQL and use of SQL function at project level

Read More

Sealed class in c# with real time example

Sealed classes and Sealed methods in C#.NET

Introduction of Sealed class:A sealed class is a class that does not allow inheritance. Some object model designs need to allow the creation of new instances but not inheritance, if this is the case, the class should be declared as sealed.To create a sealed class in C#, the class declaration should be done as:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
sealed class SealedClass   // Sealed class
    public int Add(int x, int y)
        return x + y;
class Class1 : SealedClass
    static void Main(string[] args)
        SealedClass sealedCls = new SealedClass();
      //Object creation of sealed class
        int total = sealedCls.Add(4, 5);                  
      //Calling the function
        Console.WriteLine("Total = " + total.ToString());

When you try to derive a class from sealed class compiler throw an error."'Class1': cannot derive from sealed type 'SealedClass' "

The actual mean of using sealed class is to prevent inheritance of a class, we do not want to allow some class  to extend the functionality of a class.

Advantages of sealed class in c# 
1.Sealed keyword in C# applies restrictions on the class and method
2.At class level sealed modifier prevents a class from being inherited. 

Some true fact about a sealed class in c#

* Can we create instance of sealed class in c#
   Yes, you can

* Purpose of sealed class in c# net
  Is to prevent class being inherit

* Sealed class is like the normal class but the sealed class can't inherited but it's possible can be instantiated like normal class.

* To declare sealed class we should use the sealed keyword with the class declaration.

* The sealed classes are useful in order to protect our classes not to be used by any other classes.

Sealed Method:
We can also use the sealed modifier on a method or property that overrides a virtual method or property in a base class. If we want to stop the derivation of class for the next level then we need to mark method as sealed in previous class.

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

namespace SealedClass
    class Boss
        virtual public void Work()
            Console.WriteLine("In class A");

    class TL : Boss
        sealed override public void Work()
            Console.WriteLine("In class B");
    class Employee : TL
        override public void Work() //Error: cannot override inherited member 
        {                               //TL.Work() because it is sealed  


 Also Read:

Read More