The blog has moved to the new site F10Debug.com

Monday, April 4, 2016

How oops concepts is implemented in the Asp.Net

How oops concepts is implemented in the Asp.Net 

Posted by User: Sneha Sharma

Question: 
I need a brief details about the opps concepts implemented in the Asp.Net .Though multiple inheritance is not supported in C# How can we inherit from one master page to many aspx pages.

Ans:
Multiple inheritance means one class is derived from multiple classes, which is not possible in case of c#. Which can be achieved using interface.

In case of Master page and child page, we are not deriving one child page from many master pages, we are deriving many independent child classes from one parent class.

Ex:  Here how master page and child page uses oops concepts...Many individual child classes (child class) are derived from only one master page. (Parent class)



ChildPage1: Masterpage1

ChildPage2: Masterpage1............ChildPageN: MasterPage1


Real Time Example: 

Here we have derived two child classes (About, Default child pages) from one parent class (Page class - master page)

Partial class About
       Inherits Page
End Class

Partial class Default
       Inherits Page
End Class

here we are not deriving one child page (child class) from many master pages (Parent classes)

For Ex: 

Childpage1:   MasterPage1, MasterPage2

Hope this will clear your doubts. Let me know if any questions...


Friday, April 1, 2016

C#.Net interview questions Part1

C#.Net interview questions and Answers

1) Basic OOP Concepts (OOP, Object, Class)
   a) What is OOP ?
   b) What is Object ?
   c) What is Class ?

2) What are properties of object oriented programming ? Or
    What are 4 main Pillars / Components /Concepts of object oriented programming ?

    a) What is Abstraction?

    b) What is encapsulation? Abstraction Vs Encapsulation ?

    c) What is Polymorphism? Types of Polymorphism ? Static Vs Dynamic Polymorphism ?
       Static Polymorphism ( Funcation Overloading.)    
       Dynamic Polymorphism ( Funcation Overriding.)

    d) What is Inheritance? What are the types of Inheritance?
       Implementation Inheritance
       Interface Inheritance

3) Interview questions related to Inheritance in C#.Net
    a) What is Inheritance Hierarchy? 
    b) Do .Net supports multiple inheritance? 
    c) Why don’t we have multiple inheritance in .Net? 
    d) How do you prevent a class from inherited? 
    e) If we inherit the class does the private variables also inherited?

4)  Interview questions related to Abstract class and interface
  
   e) Advantage of Interface over abstract class ?
    => A class can inherit multiple interfaces but can inherit only one class.

   f)  When to use abstract class and interface ? 
   g) What are Abstract properties ? 
   h) What is Explicit and default interface ? 
   i) Do Interface have accessibility modifier ? Ans: Yes
   j) Do Interface members have accessibility modifier ? Ans: No
   k) Examples on Interface.






Thursday, March 31, 2016

When to use Method Overriding & Method Hiding using real time example

When to use Method Overriding & Method Hiding using real time example

When to Use:

When we want different implementation in all derived classes and base class with default implementation, so if any derived class does not have there own implementation then default base class method will be called.

namespace OverridingExample
{
   //Base Class
   class Shape
    {
        //Method to be overridden in derive class
        public virtual void CalculateArea()
        {
               //Default Implemention.
            Console.WriteLine(" Default Area Calculated.");
        }
    }
    
    //Child Class
    class Circle: Shape
    {
        public override void CalculateArea()
        {
            Console.WriteLine("Circle Area Calculated.");
        }
    }
    

   class Rectangle: Shape
    {
        public override void CalculateArea()
        {
            Console.WriteLine("Rectangle Area Calculated");
        }
    }
   

   //Class Square does not override method CalculateaArea
    class Square : Shape
    {
        
    }

    class Program
    {
        static void Main(string[] args)
        {
           // Creating Object of circle class
            Shape shape1 = new Circle(); 
            shape1. CalculateArea();

            // Creating Object of rectangle class
            Shape shape2 = new Ractangel();
            shape2. CalculateArea();

            // Creating Object of Square class -> Square class does not have override method, so it will take default                     implementation of Base class
            Shape shape3 = new Square();
            shape3.CalculateArea();

            Console.ReadLine();
        }
    }
}


Thursday, March 24, 2016

Method Overriding Vs Method Hiding Using example in C#

Method Overriding & Method Hiding:

Explanation: 

-  Method overriding / Hiding occurs when child class declares a method with the same name and 
    same Method Signature as parent class.

   In below example derived class has method (overrides method) print, which has same signature as 
   print method of Parent class  (BaseClass) 

- Base class method must be virtual or overridable. 

  Here in our example Base class method name Print() is virtual.

- Child Class Method must have override keyword before return type.  // Case 1: Method Overriding
   
   Here in our example child class method name Print() having override keyword before return type.

- Child Class Method must have New keyword before return type or no keywords before it.  // Case 2: Method Hiding
   Here in our example child class method name Print1() is New & in case of print2() method it has no keywords.
- Method overriding is also called as Run Time Polymorphism/ Dynamic Polymorphism/Late Binding.

Example of Method Overriding & Method Hinding.



using System;

namespace MethodOverriding_Hiding
{

    public class BaseClass
    {
        public virtual void Print()
        {
            Console.WriteLine("Base class method - Print");
        }

        public virtual void Print1()
        {
            Console.WriteLine("Base class method - Print1");
        }

        public void Print2()
        {
            Console.WriteLine("Base class method - Print2");
        }
    }

    public class DerivedClass : BaseClass
    {
        public override void Print()
        {
            Console.WriteLine("\n" + "Derived class method - Print"); // '/n' for new line.
        }

        public new void Print1()
        {
            Console.WriteLine("Derived class method - Print1");
        }

        public void Print2()
        {
            Console.WriteLine("Derived class method - Print2");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // Normal method - It will call respective class method only 
            // No matter of virtual/ override / New keyword
            BaseClass B = new BaseClass();
            B.Print();
            B.Print1();
            B.Print2();

            DerivedClass D = new DerivedClass();
            D.Print();
            D.Print1();
            D.Print2();

            //Method Overriding
            BaseClass B1 = new DerivedClass();
            // Base - virtual, Derived - Override -> Child Class (Overriden) method will be 
            // called & its Called as Method Overriding
            B1.Print();

            // Base - virtual, Derived - New or Void -> Base class (Hidden) will be called
            // & its Called as Method Hidding
            B1.Print1();
 
// Base - void, Derived - void -> Base class (Hidden) will be called
B1.Print2();
        }
    }
}

OUTPUT:



Difference Between Method overriding vs. Method Hiding

  • In both cases parent and child class should have same method name and same signature
  • only difference is in case of Method overriding derived class should have overrides keyword
  • and in case of method hiding derived class should have New keyword.




When to use Method Overriding & Method Hiding using real time example

Sunday, November 8, 2015

Not Exists in SQL / How to check if column exists in SQL Server table

Not Exists in SQL Server / How to check if column exists in SQL Server table

Description:

This "Not Exists" keyword we generally used while inserting a new row in table. If that row (depend on keys we passed in where condition) is not exits than insert a row.

Syntax:

IF Not Exists (SQL Query)
Begin
   // Insert statement or do as per requirement. 
End

Example:

Take example of Registration page of Gmail while opening new account. It will check for that particular Email is already exists or not, if not then only it will allow you to create a account else it will ask you to choose another.

IF Not Exists (Select 1 from Users where UserEmail= 'jatin@dotnetaddas.com')
Begin
   // If this user id does not exists then it will come under this block 
  // Create User   
End
Else
Begin
  // User Already Exists.
End

So the sql query we used in above example is,

=>  Select 1 from Users where UserEmail= 'jatin@dotnetaddas.com'

what it will do is, it will check for the email we passed, if exits it will give o/p as '1' else no row will displayed.

The Same way we can make use of only 'Exits' keyword, without not, as per project requirement.

Also we can use this "Exits" and "Not Exists" SQL keywords in Where condition as below,

1) While Delete Operation, 

DELETE From Users
WHERE EXISTS 
(SELECT * FROM User WHERE UserEmail = 'jatin@dotnetaddas.com')

2) While Insert Operation,

INSERT INTO Employee
(Emp_id, Emp_name)
SELECT User_Id, User_name
FROM Users
WHERE EXISTS (SELECT *
              FROM Users
              WHERE WHERE UserEmail = 'jatin@dotnetaddas.com');

 3) While Update Statement,

Update Employee
Set Emp_Name = 
         ( SELECT User_Name FROM Users WHERE WHERE UserEmail = 'jatin@dotnetaddas.com') 
WHERE NOT EXISTS (SELECT *
              FROM Users
              WHERE WHERE UserEmail = 'Jay@dotnetaddas.com');




Friday, October 30, 2015

Visual Studio 2012 Not opening

Visual Studio 2012 Not opening

If visual studio not opening, please follow the below steps,

Go to Run -> Type “Regedit”



Run -> Regedit
Run command

Registry window will open,

Registry window

3) Microsoft -> Visual studio


4) Delete 11.0 and 11.0_config folders.

 Note:  After this changes pls. restart the system.

Friday, September 11, 2015

Case Statement in SQL Server

According to msdn : Evaluates a list of conditions and returns one of multiple possible result expressions.

The SQL Server (Transact-SQL) CASE statement is similer to IF-THEN-ELSE statement. You can use the CASE statement within a SQL statement.

Syntax:

 case 
         When expression1 then result1

         When expression2 then result2

          else result
 end