Skip to content

Instantly share code, notes, and snippets.

Comparisons in .NET

Comparisons work out-of-box only for primitive types. For others they need to be defined.

Comparisons do not work well with inheritance. It's not recommneded to implement comparisons on unsealed classes.

IComparable<T>

This interface defines CompareTo method that returns int:

  • -1 (less then)

Ansible

Overview

It is used for automation of configuration processes. You inform Ansible what is the DESIRED state and Ansible will try to achieve it, no matter what the CURRENT state is. Example: you want to have a file in a spcified location with a specified content. There ar ea few possible starting points:

  • the file does not exist - Ansible will create it
  • the file exist, but has a different content - Ansible will update the file
  • the file exists and has the right contnet - Ansible will do nothing

Random values

//Random number
let random = Int.random(1...10)

//Random array element
let array = [1, 2, 3, 4]
let randomFromArray = array.randomElement()

Overview

HttpClient uses implementations of HttpMessageHandler to do its job. The default handler is HttpClientHandler.

There may be a chain of handlers (delegating handler pattern). Messages go down throug handlers and responses go up to the HttpClient. Any handler can decide not to pass message down and return a response earlier (i.e. caching).

HttpClient configuration

_httpClient.BaseAddress = "http://www..google.pl";

IIFE

A way to make file's data non-global is to use IIFE:

(function () {
    statements
})();

OOP

There are 3 ways of using objects:

  • Object Literals
  • Constructor Functions
  • Classes

Object Literals

Arguments

Function has an arguments object containing all of the arguments passed by the called (even if function does not define any parameter, you can still pass arguments).

Arrow functions do not have this parameter.

Arrow Functions

this is inherited from the scope where arrow function was defined.

Transport Control Protocol (TCP)

Allows 2 endpoints to exchange data reliably ovet the network. It is a Transport (4th) layer of OSI.

Connection

Connection between 2 computers is identified by:

  • source IP
  • source port
@marcinjahn
marcinjahn / oceny.cs
Last active February 10, 2023 15:05
Przykład programu na zaliczenie C#
using System;
using System.Collections.Generic;
using System.Linq;
// Typy danych
record Student(IEnumerable<SubjectWithMarks> Subjects);
record SubjectWithMarks(Subject Subject, Marks Marks);
record Marks(int Semester1Mark, int Semester2Mark);