Friday 4 June 2021

FAQ--(C# .Net)

BACK

C# .Net:

All FAQ Lists-
 
1) OOP's ( Object Oriented Programming ) Concepts.
2) Boxing and Unboxing Concept in C#.
3) Value Type and reference type in C#. (Ref/Out Keyword) what do you means by Value Type and               Reference Type in C#.                   
4) Access Modifier in C#.
5) Nullable type in C#.
6) Sealed Class.
7) Properties in C#.
8) Indexes in C#.
9) Static Method and Class && Static variable.
10 Constant and Read-only.  (Very imp)
11) Serialization and deserialization in C#.
12) Partial Class.
13) Collection   & Generic Collection. (Array / ArrayList / List)
 
Pending Questions Below :-
1.How you will manage the Security for the application?

2.When we should use abstract and when Interface in real time project.

3.How to improve the performance of your application?

4.Differences between ReadOnly and Constant Keyword in C# .


Most IMP Questions Below :-

1. What is OOP"s Concept ? Explain with Examples and Coding.

Ans: OOP( Object Oriented Programming in C# .NET. )

OOP's Concepts:

  • 1.Encapsulation
  • 2. Abstraction 
  • 3. Inheritance
  • 4. Polymorphism
  • 5. Dynamic Binding
  • 6. Message Passing.
1. Encapsulation:
Rapping the data members and member function into a container(or Class) is called encapsulation. 
In Encapsulation, the variables or data of a class are hidden from any other class and can be accessed only through any member function of their class in which they are declared. As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding. The data are hide (restricted) by using access modifier (public/private/protected/internal/protected internal).
EX: A class is rapping the data members (variables, types etc.) and member function (methods) in it. So everything is inside the class only.

Class ABC
{
    
    // it can be accessible outside the class possible
    private x=10, y=20; 
    protected void show()
        {
            int a=100;
            int b=200;
        }
}

2. Abstraction :
Abstraction is achieved by using the abstract classes and abstract methods in c#.
An abstract class is an incomplete class or special class we can’t be instantiated. The purpose of an abstract class is to provide a blueprint for derived classes and set some rules what the derived classes must implement when they inherit an abstract class. We can use an abstract class as a base class and all derived classes must implement abstract definitions. 

Points to be remember:
1.An Abstract class does not mean that it only contain abstract methods. An Abstract class can also contain non-abstract methods also.
2. Abstract class can also work with get and set accessory.
  • A user must use the override keyword before the method which is declared as abstract in child class, the abstract class is used to inherit in the child class.
  • An abstract class cannot be inherited by structures.
  • It can contains constructors or destructors.
  • It can implement functions with non-Abstract methods.
  • It cannot support multiple inheritance.
  • It can’t be static
  • .
3. Inheritance: (Reusability of the CODE)
It can be possible to re-use the same code written in a class in another class by using Inheritance.
  • Super Class: The class whose features are inherited is known as super class(or a base class or a parent class).
  • Sub Class: The class that inherits the other class is known as subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods.

Syntax:  (Symbol of inheritance is colon : )

class derived-class : base-class  
{  
   // methods and fields  
      .....
}
 Types of Inheritance in C#
    - Single Inheritance
    - Multilevel Inheritance.
    - Hierarchical Inheritance.

*Single Inheritance: In single inheritance, subclasses inherit the features of one superclass. In image below, the class A serves as a base class for the derived class
 
*Multilevel Inheritance: In Multilevel Inheritance, a derived class will be inheriting a base class and as well as the derived class also act as the base class to other class. In below image, class A serves as a base class for the derived class B, which in turn serves as a base class for the derived class C.
 
 
 

 
*Hierarchical Inheritance: In Hierarchical Inheritance, one class serves as a superclass (base class) for more than one subclass. In below image, class A serves as a base class for the derived class B, C, and D. 

*Multiple Inheritance(Through Interfaces):In Multiple inheritance, one class can have more than one superclass and inherit features from all parent classes. Please note that C# does not support multiple inheritance with classes. In C#, we can achieve multiple inheritance only through Interfaces. In the image below, Class C is derived from interface A and B.
  1. *Hybrid Inheritance(Through Interfaces): It is a mix of two or more of the above types of inheritance. Since C# doesn’t support multiple inheritance with classes, the hybrid inheritance is also not possible with classes. In C#, we can achieve hybrid inheritance only through Interfaces.



IMPORTANT Points:

a) A superclass can have any number of subclasses. But a subclass can have only one superclass. This is because C# does not support multiple inheritance with classes. Although with interfaces, multiple inheritance is supported
b) A subclass inherits all the members (fields, methods) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.
c) A subclass does not inherit the private members of its parent class. However, if the superclass has properties(get and set methods) for accessing its private fields, then a subclass can inherit.

4. Polymorphism:
Poly means "many" and morphs means "forms" -- Many Forms
So one name but different forms.

POINTS to be noted-- For Overloading:
Main Point : The method parameter can not be same and can not be same order.

1.) Method overloading : When the multiple methods having the same method name but different signature(parameters) is called overloading. most important if the
method name and signature also same then the program will throw compile time error like ""The program is ambiguous because it is already define a member as sum(method name) with the same parameter type". you cannot declare two methods with the same signature and different return type.
EX:
using System;

public class Program
{
public void load(int x, int y)
{
Console.WriteLine(x+y);
}
public void load(int a, int b)
{
Console.WriteLine(a+b);
}

public static void Main()
{
Program  obj=new Program();
obj.load(10,30);
Console.WriteLine(obj);
}
}

2) Why do we need Method Overloading?

If we need to do the same kind of the operation in different ways i.e. for different inputs. In the example described below, we are doing the addition operation for different inputs. It is hard to find many different meaningful names for single action.


POINTS to be noted for Overriding:

1.) A derived class can override a base class member only if the base class member is declared as virtual or abstract.


POINTS For Virtual/ Override/ Base       Keyword Use:

In C# we can use 3 types of keywords for Method Overriding:

  • virtual keyword: This modifier or keyword use within base class method. It is used to modify a method in base class for overridden that particular method in the derived class.
  • override: This modifier or keyword use with derived class method. It is used to modify a virtual or abstract method into derived class which presents in base class.
  • base Keyword: This is used to access members of the base class from derived class. It basically used to access constructors and methods or functions of the base class. The base keyword cannot use within a static method. Base keyword specifies which constructor of the base class should be invoked while creating the instances of the derived class.

Use of Base keyword: 

  • Call methods or functions of base class from derived class.
  • Call constructor internally of base class at the time of inheritance.


  • Paul Blog
  • 1 comment:

    FAQ--(3- Tier Project)

    BACK   https://meeraacademy.com/3-tier-architecture-example-in-asp-net-c/ 1. Presentation Layer (UI – User Interface Layer) 2. Busine...