Search This Blog

Saturday, January 26, 2019

Static

Static keyword has different role in different places for C#. When we declare static that means only single copy will be generate.

Static container can only contains static members


It is used in below places-
  • Class
  • Method
  • Field
  • Properties
  • Constructor


Static Class

  • Only contain all static members like static methods, static fields, static properties and static constructor.
  • Any instance or non-static member can not be there in the Static Class.
  • If we need to create all the members as static then we can create static class.
  • Can not create instance of such class.
  • Sealed.
  • Cannot contain Instance Constructors




Static Methods

  • Only contain all static fields
  • Non-static fields are not allowed in static methods
  • Method can be access using class only, no instance is needed or can access.
  • Single copy of static method will be shared among all the instances.



Static Fields


  • Single copy of fields/variables get created and shared among all the instances.
  • If static variable value has been change using one instance then all other instance will get that changed value.

Static Property

  • Can be access using class only.
  • Using instance it can not be access.

Static Constructor


  • Access modifier are not allowed.
  • Static Constructor as it(class constructor) execute prior to any other constructor (instance constructor).
  • Can instantiate value of static fields only.
  • Non-Static fields is not allowed within the scope.



More About Static:


  • Static methods are not allowed in the interface.
  • Access modifiers are not allowed in the interface and static constructor.
  • Static class can't be inherit from interface/class/static class.
  • Static class can only be inherit from object. ??
  • Inheritance from static class in not possible as static classes are sealed.
  • Inherited Static method can not be marked as override, virtual or abstract.
  • Inherited Static methods can be marked as new.



Friday, January 11, 2019

Structured/Imperative/Functional/Procedural Programming

Structured Programming 


  • Top-down analysis
    • Problem broken down into small piece (sub-problems) where each one has some significance.
    • Each small piece of problems are individually solved and steps are clearly stated.
  • Modular Programming
    • Code is broke down into small groups of instructions
    • These groups are knows as modules or subprograms or subroutines or methods.
    • Avoid jumps (unconditional GoTo) as non-traceable
  • Structured Code
    • Divide modules into further small units of code

  • Follow Top Down design model 
  • Maintainable Code
  • Systematic Organization
  • Reusable code block
  • Subdivision of program into functions
  • Hierarchy of task
  • Simple and easy to understand the code
  • Avoid unconditional Goto

Un-Structured code
  • Unconditional Goto 


Imperative languages


  • Imperative programming is a paradigm of computer programming in which the program describes a sequence of steps that change the state of the computer.
  • Unlike declarative programming, which describes "what" a program should accomplish, imperative programming explicitly tells the computer "how" to accomplish it.
  • To make programs simpler for a human to read and write, imperative statements can be grouped into sections known as code blocks.


Functional Programming


  • Functional programming (FP) is about passing data from function to function to get a result.
  • In FP, functions are treated as data, meaning you can use them as parameters, return them, build functions from other functions, and build custom functions.
  • A functional approach involves composing the problem as a set of functions to be executed.
  • In software, everything is a statement, unless it is a function. 


Procedural Programming


  • Procedural programming is a programming paradigm, derived from structured programming
  • Based upon the concept of the procedure call. Procedures
  • Also known as routines, subroutines, or functions, simply contain a series of computational steps to be carried out.
  • Any given procedure might be called at any point during a program's execution, including by other procedures or itself.
  • Procedural programming (PP), also known as inline programming takes a top-down approach.
  • It is about writing a list of instructions to tell the computer what to do step by step.
  • It relies on procedures or routines.
  • Procedural programming is a type of imperative programming in which the program is built from one or more procedures (also termed subroutines or functions).
  • Procedural programming could be considered a step towards declarative programming.
  • A programmer can often tell, simply by looking at the names, arguments, and return types of procedures (and related comments), what a particular procedure is supposed to do, without necessarily looking at the details of how it achieves its result.
  • At the same time, a complete program is still imperative since it fixes the statements to be executed and their order of execution to a large extent.