#WTHI? The 4 principles of OOP C#

The four basic principles of object-oriented programming are:

Abstraction: Model the necessary attributes and interactions of entities as classes to define an abstract representation of a system.

Encapsulation: Hide the internal state and functionality of an object and allow only access through a public set of functions.

Inheritance: Ability to create new abstractions based on existing abstractions.

Polymorphism: The ability to implement inherited properties or methods in different ways on various abstractions.

#WTHI? SOLID

It is a series of principles and good practices that should be taken as a basis for software development to achieve a code that is cleaner, more maintainable, more scalable in the future and less prone to errors.

SOLID is the acronym for “Single Responsibility Principle“, “Open/Closed Principle“, “Liskov Substitution Principle“, “Interface Segregation Principle“, and “Dependency Inversion Principle“, where:

S: Single Responsibility Principle – Each module must have a single reason to change.
O: Open/Closed Principle – The code should be Open to extend it and add new features, and Closed to modifications, except those that must be made if an error is found.
L: Liskov Substitution Principle – A derived class must be able to be substituted for its base class.
I: Interface Segregation Principle – Several purpose-specific interfaces should be used, rather than a few large interfaces.
D: Dependency Inversion Principle – Must depend on abstractions, not concrete classes.

Classes and Methods in C#

Private class
It is a class whose members can only be accessed by classes in the same environment.

Public class
It is a class whose members can be accessed by classes from any environment.

Protected class
It is a class whose members can only be accessed by the same class.

Abstract class
It is an incomplete class that defines the members that a base class must have.
It cannot be instantiated, it will only inherit.

Sealed class
It is a class that does not allow to be inherited, only instantiated

Private method
Is a method that is only accessible from the same class

Public method
Is a method that can be accessible from any class

Abstract methods
Is a method without implementation that must be implemented when inheriting the class

Virtual method
Is a method that can be overridden by inheriting the class

C# – Execute a Stored Procedure with Output parameter

using System.Data.SqlClient;

SqlParameter pParameterIn = new SqlParameter(“@ParameterIn“, “AnyValue”);
pParameterIn.Direction = System.Data.ParameterDirection.Input;

SqlParameter pParameterOut = new SqlParameter(“@ParameterOut“, -1);
pParameterOut.Direction = System.Data.ParameterDirection.Output;

var recordsAffected = _vmsDBContext.Database.ExecuteSqlCommand(
sp_YourStoredProcedure @ParameterIn, @ParameterOut OUT
, parameters: new[] {
pParameterIn
, pParameterOut
}
);

var answer = pParameterOut.Value;

Probado en:

Net 4.7