- What is OOP
- OOP stands for object oriented programming is a programming language in which programs organized around data or objects. An object can be defined as a data field which has unique attributes and behavior
- Write concepts or principles of OOP
- Abstraction
- Abstraction is one of the principle of object oriented programming. It is used to display only necessary and essential features of an object to outside the world
- Encapsulation
- Encapsulation binds together code and the data it manipulates and keeps them both safe inside a class from outside interference and misuse. Only public methods or functions can accessible form other objects
- Inheritance
- Inheritance means the ability to create new classes based on an existing class. so derived classes can access all the properties and methods of base class.
- Polymorphism
- Polymorphism provides the ability to a class to have multiple implementations with the same name.There are two types of polymorphism in C#
- Static/Compile Time Polymorphism
- Method Overloading
- In a class we have methods with same name but different parameters
- Operator Overloading
- You can redefine or overload most of the built-in operators available in C#. Thus a programmer can use operators with user-defined types as well.
- Dynamic/Runtime Polymorphosm
- Virtual / Overriding Method
- What is Abstraction?
- Abstraction is one of the principle of object oriented programming. It is used to display only necessary and essential features of an object to outside the world
- Abstract Class in C#
- An abstract class is a special type of class that cannot be instantiated
- An abstract class is designed to be inherited by sub-classes that either implement or override its methods
- In other words, abstract classes are either partially implemented or not implemented at all
- You can have functionality in your abstract class—the methods in an abstract class can be both abstract and concrete
- An abstract class can have constructors—this is one major difference between an abstract class and an interface.
- Abstract Methods in C#
- An Abstract method is a method without a body.
- The implementation of an abstract method is done by a derived class.
- When the derived class inherits the abstract method from the abstract class, it must override the abstract method. This requirement is enforced at compile time and is also called dynamic polymorphism
- Constructors
- Constructor is a method which has same name as class name
- Constructors are class methods that are executed automatically when an object of a given type is created
- Finalizers
- It is used to dispose instances of classes
- In the .NET Framework, the garbage collector automatically manages the allocation and release of memory for the managed objects in your application. However, you may still need finalizers to clean up any unmanaged resources that your application creates.
- There can be only one finalizers for a class.
- Access Modifiers and Access Levels
- We can specify access modifiers to methods and properties of the class to manage access level of it
- public
- The type or member can be accessed by any other code in the same assembly or another assembly that references it.
- private
- The type or member can only be accessed by code in the same class.
- protected
- The type or member can only be accessed by code in the same class or in a derived class from any assembly.
- internal
- The type or member can be accessed by any code in the same assembly, but not from another assembly.
- protected internal
- The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.
- private protected
- The type or member can be accessed by code in the same class or in a derived class within the base class assembly
- Virtual Keyword
- Allows a class method to be overridden in a derived class.
- Override Keyword
- It is used to override a virtual or abstract method defined in base class.
- Abstract Method
- We must override abstract methods in derived or base class
- new
- the new keyword explicitly hides a member that is inherited from a base class.
public class BaseC { public int x; public void Invoke() { } } public class DerivedC : BaseC { new public void Invoke() { } }- Interfaces
- Interface can have methods, properties, events, and indexers as its members. But interfaces will contain only the declaration of the members. The implementation of interface’s members will be given by class who implements the interface
- Interfaces can’t have private members.
- By default all the members of Interface are public and abstract
- We can implement multiple interfaces in a class
- We must implement all methods of interface to the class who implements the interface
- Partial Class
- It provides a special ability to implement the functionality of a single class into multiple files
- Generics
- it enables us to create classes, interfaces, and methods that work with different data types without having to define the data type explicitly
- Reflection
- Dynamically know properties and methods in the object and also create code
- Extension Methods
- Extension methods allow you to inject additional methods without modifying, deriving or recompiling the original class
- Async
- We can create async method, which calls asyncronously
- Await
- When we create async method, we must add keyword await in the async method
- The await operator is applied to a task in an asynchronous method to insert a suspension point in the execution of the method until the awaited task completes
- Task
- .NET framework provides Threading.Tasks class to let you create tasks and run them asynchronously.
- A task is an object that represents some work that should be done. The task can tell you if the work is completed and if the operation returns a result, the task gives you the result.
- It can be used whenever you want to execute something in parallel. Asynchronous implementation is easy in a task, using’ async’ and ‘await’ keywords.
- Delegates
- the delegates in C# are the type-safe function pointer means they hold the reference of a method and then calls that method for execution
- Single case delegate
- If a delegate is used for invoking a single method then it is called a single cast delegate or unicast delegate. In other words, we can say that the delegates that represent only a single function are known as single cast delegate.
- If a delegate is used for invoking multiple methods then it is known as the multicast delegate. OR the delegates that represent more than one function are called Multicast delegate.
- ArrayList vs List<>
- List<T> is a generic class. It supports storing values of a specific type without casting to or from object (which would have incurred boxing/unboxing overhead when T is a value type in the ArrayList case).
ArrayListsimply storesobjectArrayListbelongs to the days that C# didn't have generics. It's deprecated in favor ofList<T>. You shouldn't useArrayListin new code that targets .NET >= 2.0 unless you have to interface with an old API that uses it.- IEnumerable Vs IQueryable
- IEnumerable exists in the System.Collections namespace.
- IEnumerable is suitable for querying data from in-memory collections like List, Array and so on.
- While querying data from the database, IEnumerable executes "select query" on the server-side, loads data in-memory on the client-side and then filters the data.
- IEnumerable is beneficial for LINQ to Object and LINQ to XML queries.
- IQueryable exists in the System.Linq Namespace.
- IQueryable is suitable for querying data from out-memory (like remote database, service) collections.
- While querying data from a database, IQueryable executes a "select query" on server-side with all filters.
- IQueryable is beneficial for LINQ to SQL queries.
- Equals and ==
- “==” does type checking during compile time
- while “Equals” is more during runtime
- “==” works with nulls but “Equals” crashes when you compare NULL values
- Task vs Thread
- The Thread class is used for creating and manipulating a thread in Windows
- A Task represents some asynchronous operation and is part of the Task Parallel Library, a set of APIs for running tasks asynchronously and in parallel
- A task can have multiple processes happening at the same time. Threads can only have one task running at a time.
- A Task is a higher level concept than Thread.
No comments:
Post a Comment