Notes on .NET, C#, self-hosted LLMs, Android and whatever else I break on the way.
Written since 2012, migrated from WordPress to a few static files.
Who is writing this?
defines standard way for middleware to be used in a pipeline to handle requests and provide responses
ASP.NET Core applications can interoperate with OWIN-based applications, servers and middleware
Microsoft.AspNetCore.Owin package provides two adapter implementations:
ASP.NET Core to OWIN
OWIN to ASP.NET Core
This allows ASP.NET Core to be hosted on top of an OWIN compatible server/host or for other OWIN compatible components to be run on top of ASP.NET Core.
each node is expression (method call, equality comparison, binary operation etc.) representing a piece of code
you can compile expression tree and run code it represent
enables dynamic code generation at runtime
LINQ queries on DBs are implemented with Expression Trees
used in the dynamic language runtime (DLR)
anonymous lambda expression can be converted to ExpressionTree via compiler (i.e. x => x*2 can be represented as tree instead of delegate or anonymous lambda function)
consistent model for working with data from various kinds of sources and formats (XML, SQL, ADO.NET, Datasets, .NET collections etc) 3 stages of working with LINQ: obtain data source create the query execute the query data sources implements IEnumerable<> and are called queryable types IQueryable<> interface inherits from IEnumerable<> generally it is better to use LINQ via IQueryable<> which produces deferred query instead of producing result immediately queries can be executed multiple times queries can be forced immediate execution via Count(), Max(), ToList() or ToArray() etc. LINQ to DB libraries (like EntityFramework) usually are implemented via Expression …
tracked entities are saved during SaveChanges() call entities being tracked when they are: returned from DB attached to context added as subentity tracking can be disabled (AsNoTracking() i.e.) Further read:
https://learn.microsoft.com/en-us/ef/core/change-tracking/
Pattern matching is used for:
testing expression to check if some value have certain characteristics safer compare because ‘==’ and ‘!=’ can be overloaded Examples:
a is int number sequence is IList<T> list switch statement:
command switch { Operation.SystemTest => RunDiagnostics(), Operation.Start => StartSystem(), Operation.Stop => StopSystem(), Operation.Reset => ResetToReady(), _ => throw new ArgumentException("Invalid enum value for command", nameof(command)), }; switch with ranges:
tempInFahrenheit switch { (> 32) and (< 212) => "liquid", < 32 => "solid", > 212 => "gas", 32 => …
obtain information about types and members at runtime create instances, invoke or access them dynamic code generation Further read:
https://learn.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/reflection
· 35 words · ~1 min read
· updated
· in .NET, interview
Type Command framework-dependent executable for the current platform. dotnet publish framework-dependent executable for a specific platform. dotnet publish -r <RID> --self-contained false framework-dependent binary. dotnet publish self-contained executable. dotnet publish -r <RID> Further read:
https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent
Ahead of the time compilation to machine code
produces self-contained application which: starts quicker uses less memory does not require .NET runtime installed it is better for workloads with high deployment instances (clouds) makes runtime code generation impossible not all libraries are compatible Further read:
https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/
Just - in - time compiler.
part of CLR for all .net programs for all .net languages converts MSIL to native machine code compiles code when it is necessary at runtime also it is possible to pre-compile to native code at compile time instead Further read:
https://www.geeksforgeeks.org/what-is-just-in-time-jit-compiler-in-dot-net/
can be class or struct creates methods overrides for enforcing value equality instead of reference equality: Object.Equals Object.GetHashCode operators == != implements IEquatable<> parameter implements ToString supports deconstruction supports with expression meant to be immutable Positional records is a more concise syntax for record:
primary constructor parameters match the positional parameters of the record declaration public init-only properties for each parameter Further read:
https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/records#characteristics-of-records
· 26 words · ~1 min read
· updated
· in .NET, interview
We can.
for some critical part of application code using GC.TryStartNoGCRegion method. using CER (Constrained Execution Regions) (obsolete) with GC LatencyModes Further read:
https://learn.microsoft.com/en-us/dotnet/api/system.gc.trystartnogcregion?redirectedfrom=MSDN&view=net-7.0#overloads https://learn.microsoft.com/en-us/dotnet/framework/performance/constrained-execution-regions?redirectedfrom=MSDN https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/latency
automatic memory management allocates and releases memory prevents memory leaks and accessing dead objects provides memory safety virtual memory space defragments/compacts memory heap have 3 generations 0 - for new objects; 1 - for objects that lives through GC from 0 2 - for long living objects from 1 and 0 also Large Objects Heap (LOH) for big objects like arrays over 85,000 bytes Further read:
https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals?source=recommendations
allows for matching signatures of delegates and method groups
to assign to delegates from method that returns more derived types - covariance
to assign to delegates from method that returns less derived types - contravariance
Covariance and Contravariance are supported in Generics for implicit conversions for type parameters
allows method to have more derived return type than defined by generic type parameter of the interface
this allows implicit conversions from one generic interface to another (from IEnumerable<string> to IEnumerable<object> even if first does not inherits from second)
allows generic types to have less derived argument types than specified by the generic parameter of the interface (implementation of IEqualityComparer<BaseClass> can be implicitly converted to IEqualityComparer<DerivedClass> because IEqualityComparer.Equals is contravariant)
implicit conversions works for interfaces but not classes that implement from those interfaces (i.e. this won’t work List<Object> list = new List<String>())
Assignment compatibility is when object of a more derived type is assigned to an object of a less derived type.