C# course 3

Several usefull things:

A. Piotr Gankiewicz C# course : https://piotrgankiewicz.com/courses/becoming-a-software-developer/
B. How to load external library in VisualStudio:

  • using Nutget in VisualStudio
  • interesting library : EntityFrameWork – ORM for C#

C. Your own DLL is created with project: ClassLibrary in VisualStudio

D. Documentation Autogenerator – Swagger (the same as for php): https://swagger.io/

  1. Access modificators in class
    public – in the whole solution you can use chosen class/ property/ constructor/ method
    private – property/ method accesible only in chosen class
    protected – property/ method accesible in chosen class and in classes, which inherit from chosen class
    internal – public class, but only in chosen project (it is not accessible outside library)

Good practises:
method get-always public
method set-always private

  1. Inheritance
  • we create inheritance after „:”
public class Student:Entity
  • inheritance from many classes
    Class can inherit only from one class in C#. If we want to have inheritance from many classes, we need to use interfaces like in Java.
  1. Virtual Abstract Override
  • it is used to override methods in child class from parent class
//in parent class
public virtual string MetaData()
{ return $"Id:{Id},createdAt:{CreatedAt},UpdatedAt:{UpdatedAt}"; }
  • in child class it must be done like that:
public override string MaetaData() //method from parent class is overriden in child class
{
//do sth different than in parent class
}

3. Abstract class – no object can be initialized from it

public abstract class Entity
  • responsibility of implementation methods of this abstract class is delegated to child class. So we have to declare all of the methods like that in abstract class (it is similar to C++ headers’ declarations):
public abstract void Introduce();
  • in child’s class this method should be implemented like this:
public override void Introduce()
{
Console.WriteLine("aaa");
}
  1. Static – static methods
  • Static class – class, which properties are accesible without the need of creating the object. They are used for :
  • defining global constants
  • creating helper function
public static class LoginHelper
{
public static bool IsEmail(string login)
{
if (login.contains('@'))
{ return true;}
else
{return false;}
}
}
  • Now we can use it anywhere in our project:
LoginHelper.IsEmail("ddd");

Opublikowany w C#Tagged

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany.