Giter VIP home page Giter VIP logo

beqomtask's Introduction

Class or Struct

Struct: A struct is a value type. When a struct is assigned to a new variable or passed to a method, a copy of the value is passed, not the reference. Structs are typically allocated on the stack, which gives us a performance benefits, in case of small, frequently used types. Structs cannot inherit from another struct or class, and cannot be the base of a class. All structs implicitly inherit from System.ValueType.

Class: A class is a reference type. When a class instance is assigned to a new variable or passed to a method, the reference to the instance is passed. Classes are allocated on the heap, garbage collector is used to manage their memory.

Structs are generally used for small, lightweight objects, while classes are used for more complex objects and/or for inheritance and polymorfism.

Variance

Covariance allows a method to return a more derived type than that specified by the generic type parameter. This is useful when we want method to return a type that is a subclass of the specified type. It is useful when working with a hierarchy of objects. We can write more general code that can handle more specific types.

Example:

IEnumerable cats = new List(); IEnumerable animals = cats;

Contravariance, allows a method to accept parameters of less derived types than that specified by the generic type parameter. It's used in situations where we need to work with a more general type than specified. It's particularly useful in scenarios with delegates or event handling where a more general type is better. it increases usability, since we can write methods that work with more general types.

Example:

IComparer animalComparer = new AnimalComparer(); IComparer catComparer = animalComparer;

Thread safe

Example1 - Using Interlocked.Increment

int sharedVariable = 0;

int newValue = Interlocked.Increment(ref sharedVariable);

Example 2 - Using lock

int sharedVariable = 0; private readonly object lockObject = new object();

lock(lockObject) { sharedVariable++; }

Monad

Check TestProject1 project inside this solution

Refactoring

Check BeqomTestSolution and Tests projects inside this solution

beqomtask's People

Contributors

rufat3110 avatar rufius avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.