← Back to Tutorials Chapter 15

References

A condensed reference for .NET Core runtime, libraries, SDK commands, compiler switches, API surface, and NuGet packaging. Bookmark this chapter for quick lookup during development.

.NET Core Runtime Reference

The runtime (dotnet) hosts and executes managed applications. Key concepts:

dotnet --info                          # Runtime environment details
dotnet --list-runtimes                 # Installed runtimes
dotnet --list-sdks                     # Installed SDKs
dotnet --version                       # Current SDK version

Runtime Configuration

Runtime behavior can be tuned via runtimeconfig.json or environment variables:

{
  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true,
      "System.GC.Concurrent": true,
      "System.Threading.ThreadPool.MinThreads": 4,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

Compiler Reference (csc / dotnet build)

The C# compiler (csc) is invoked automatically by dotnet build. Key switches:

SwitchDescription
-target:exeBuild a console executable
-target:libraryBuild a DLL
-out:<file>Specify output file name
-optimize+Enable compiler optimizations
-langversion:12Set C# language version
-nullable:enableEnable nullable reference types
-define:DEBUGDefine preprocessor symbol
-p:<prop>=<val>Pass MSBuild property (via dotnet build)
dotnet build -p:Optimize=true -p:DefineConstants=TRACE
dotnet build -p:WarningLevel=5 -p:TreatWarningsAsErrors=true
.NET Core reference sheet

API Reference

The .NET Base Class Library provides thousands of types. Below are the most essential namespaces:

System

Object, String, Int32, Boolean, DateTime, TimeSpan, Guid, Uri, Version, Enum, Convert, Math, Random, Console, Environment.

string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
int hash = "hello".GetHashCode();
Guid id = Guid.NewGuid();
DateTime now = DateTime.UtcNow;

System.Collections

List<T>, Dictionary<K,V>, HashSet<T>, Queue<T>, Stack<T>, ArrayList, Hashtable, IEnumerable<T>, ICollection<T>, IReadOnlyList<T>.

var dict = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2 };
var list = new List<int> { 1, 2, 3 }.AsReadOnly();

System.IO

File, FileInfo, Directory, DirectoryInfo, Path, StreamReader, StreamWriter, FileStream, MemoryStream, BinaryReader, BinaryWriter.

string content = File.ReadAllText("data.txt");
var files = Directory.EnumerateFiles(@"C:\logs", "*.log");

System.Linq

Enumerable provides extension methods: Where, Select, OrderBy, GroupBy, Aggregate, Any, All, Count, First, FirstOrDefault, Single, Skip, Take, Distinct.

var result = numbers.Where(n => n > 5).Select(n => n * 2).OrderByDescending(n => n).ToList();

System.Threading.Tasks

Task, Task<T>, ValueTask, ValueTask<T>, Parallel, Task.Run, Task.WhenAll, Task.WhenAny, CancellationToken, CancellationTokenSource.

var data = await httpClient.GetStringAsync(url);
var results = await Task.WhenAll(task1, task2, task3);
For the full API reference, visit docs.microsoft.com/dotnet/api.

NuGet Package Reference

NuGet is the .NET package manager. Key commands and conventions:

dotnet add package Newtonsoft.Json --version 13.0.3
dotnet remove package Newtonsoft.Json
dotnet list package

# Package reference in .csproj:
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Common package sources: nuget.org, GitHub Packages, Azure Artifacts, and local/network feeds.

Package Versioning

NuGet uses semantic versioning (semver): Major.Minor.Patch[-prerelease]. Use floating versions with caution:

<PackageReference Include="MyLib" Version="2.*" />   
<PackageReference Include="MyLib" Version="*-*" />     
Exercise: Using only the API reference above, write a complete .NET console application that reads all .txt files from a directory, counts the frequency of each word across all files, and outputs the top 10 most frequent words. Use System.IO for file access, System.Linq for grouping/ordering, and System.Collections.Generic for the dictionary.