Thursday, May 31, 2018

ASP.NET Life-Cycle Events

  1. PreInit,
  2. Init,
  3. InitComplete,
  4. PreLoad,
  5. Load,
  6. LoadComplete, 
  7. PreRender,
  8. PreRenderComplete
  9. SaveStateComplete
  10. Render
  11. Unload.


ASP.NET Page Life Cycle stages

General Page Life-Cycle Stages
Stage
Description
Page request
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
Start
In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. The page also sets the UICulture property.
Initialization
During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
Load
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Postback event handling
If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page. (There is an exception to this sequence: the handler for the event that caused validation is called after validation.)
Rendering
Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream object of the page's Response property.
Unload
The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.

Four Pillars of OOP ?

  • Abstraction
  • Polymorphism
  • Inheritance
  • Encapsulation are four pillars of Object Oriented Programming.

What's inheritance ?

When an object or class is based on a parent object or class taking on its characteristics.

Multiple Inheritance possible in C# ?
No. though we can implement class with multiple interfaces.

What’s encapsulation & abstraction?

Encapsulation: Prevents access to implementation details.
example: private methods / member variables inside an interface.

Abstraction: allows making relevant information visible. Abstraction can be done by using Abstract keyword to the classes.
example: public methods or data with in interfaces / abstract classes.

What’s POLYMORPHISM?

It’s when classes have different functionality while sharing the same interface.
REMEMBER TO NOTE!!!: Interfaces or abstract classes can be used

What are Static classes?

Static classes are used to create data and functions that can be accessed without creating an instance of the class. We use them when there is no data or behavior in the class that depends on object identity. So they: 
  • Only contain static members.
  • Cannot be instantiated.
  • They cannot contain Instance Constructors
  • Are sealed.

What’s an INTERFACE?

They're used to specify methods and properties that a derived class
will have access to.

  • Like a contract. If a class implements an interface, the interface guarantees that the class contains specific methods specified.
  • Interfaces DOES NOT contain code or data
A class can implement any no.of interfaces, and interfaces can be instantiated.


Difference b/w Reference Vs Value Types ?


  • Reference types are objects that store references to the actual data.
    • example: Class, Interface, delegate, object & string.
  • Value types actually hold values. Assigning one value type to another literally copies that value.
    • example: Structs, enums, bools, numeric types 

Tuesday, May 29, 2018

Is it possible to store different list types in a single generic list?

Yes, It is possible by creating a list of list objects. 
List<List<object>> list = new List<List<object>>();

What’s an ABSTRACT CLASS? Why and when should we use an abstract class?

What’s an ABSTRACT CLASS?
Similar to interfaces but cannot be instantiated, and are frequently either partially implemented, or not at all implemented. 
Different from interface in that:
  • A class can inherit from only one abstract class but can implement an unlimited number of  interfaces.
  • Abstract classes DO contain code & data.
  • You can specify methods as ‘virtual’ to force derived classes to create its own implementation.
Problems without abstract class:
  • Duplication of code. So, code maintainability will be big issue.
  • With implementation of concrete (non-abstract) BASE CLASS, developer can instantiate and use the base class as actual classes, which is not intended to do.
So, in short, we should create an ABSTRACT CLASS, 
  1. When want to move the common functionality of 2 or more related classes into a base class and 
  2. When we don't want the base class to be instantiated.

Monday, May 28, 2018

Understand the document tab features

Tools => Options => Environment => Tabs and Windows

A better way to redock a tool window

Ctrl + Double click mouse

Paste JSON/XML as class

Shortcut:
1. Copy JSON Object data.
2. Goto Visual Solution and a .cs file and Menu Edit => Past Special => Past JSON as Classes.

Move code with keyboard shortcuts

Short cut
Select code block to move and press alt + up / down Arrow.

Short cut settings will available @ Tools => Options => Environment => Keyboard.


Select vertical sections of code with Box Selection

short cuts:
1. alt + drag mouse
2. Shift + alt + downArrow, press -> (right arrow)

Brace matching in C#

Matches all braces start and end, like (), [], {}, etc..
Keyboard Short Cut: Ctrl + ] 

To change color of brace matching: Goto
Tools => options => Environment => Fonts&Colors => BraceMatching (Display Items).

Reference Highlighting

Short cut to navigate on all references of a word:
1. Select any word, which highlights with grey background.
2. Keyboard shot cut: Ctrl + Shift + Up  / Down Arrow.

A note on comparison operators in JavaScript

A note on comparison operators in JavaScript:
some people using == and != in their tests for equality and non-equality. These are valid operators in JavaScript, but they differ from ===/!==
The former versions test whether the values are the same but not whether the values' datatypes are the same. The latter, strict versions test the equality of both the values and their datatypes. The strict versions tend to result in fewer errors, so we recommend you use them.

Thursday, May 24, 2018

Difference between let and VAR in JS
The let statement declares a block scope local variable, optionally initializing it to a value.
Description: let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.
An explanation of why the name "let" was chosen can be found here.
Scoping rules:
Variables declared by let have their scope in the block for which they are defined, as well as in any contained sub-blocks.
The main difference is that the scope of a var variable is the entire enclosing function.
see full details about let with examples.