Esta página aún no está traducida al español. Leer la versión en inglés

System.Core overview

What the standard library, System.Core, offers - by namespace, with the main types of each.

Última actualización: 5 min de lectura Editar en GitHub

En esta página

System.Core is the standard library every program is built against. It is written in Antril and installed compiled, as System.Core.dll next to larva. To see any type's members, use larva show (for example larva show --no-bodies --public System.List) or hover over it in the editor.

AntrilRun
import System;
import System.IO;
import System.Text;

into namespace Tour
{
	Main()
	{
		Dictionary<str, i32> stock = new Dictionary<str, i32>();
		stock["apples"] = 3;
		stock["pears"] = 5;
		Console.WriteLine(stock["pears"] + stock.Count);

		File.WriteAllText("notes.txt", "one\ntwo\n");
		loop (str line in File.ReadAllLines("notes.txt"))
			Console.WriteLine(line.ToUpper());

		JsonValue doc = JsonValue.Parse("{ \"name\": \"Ana\", \"tags\": [\"a\", \"b\"] }");
		if (doc.Get("name") is JsonValue name)
			Console.WriteLine(name.AsString);

		Regex date = new Regex("(\\d+)-(\\d+)");
		Console.WriteLine(date.Replace("10-31", "$2/$1"));

		Console.WriteLine(Math.Sqrt(2.0));
		Console.WriteLine(String.Join(", ", "a,b,c".Split(',')));
	}
}
Terminal
larva run
7
ONE
TWO
Ana
31/10
1.4142135623731
a, b, c

System

The core types and everything most programs use.

Area Types
Primitives Int8 … Int256, UInt8 … UInt256, Float16 … Float256, Boolean (the types behind i32, f64…): Parse, ToString, MinValue, MaxValue, NaN, Epsilon…
Numbers INumber<T> and ISignedNumber<T> (the number and snumber constraints), Number, NumberFormat.
Text String (str), StringBuilder, Char (functions on code points), Unicode (UTF-8 and UTF-16 conversions).
Console Console: Write, WriteLine, ReadLine, and the standard streams.
Math Math: Abs, Min, Max, Clamp, Sign, Gcd, Sqrt, ISqrt, Pow, Exp, Log, Log2, Log10, Sin, Cos, Tan, Asin, Acos, Atan, Atan2, Floor, Ceiling, Truncate, Round, and PI, E, Tau. Each works on any number type, exactly on integers and on f128/f256. Random makes random numbers.
Collections List<T>, Dictionary<K, V>, HashSet<T>, SortedDictionary<K, V>, SortedSet<T>, Stack<T>, Queue<T>, LinkedList<T>, PriorityQueue<T>, KeyValuePair<K, V>, Span<T>.
Arrays Array (Sort, BinarySearch, Sum, Min, Max, Average…) and Lists (the same for lists).
Tuples and records ValueTuple, Tuple (any number of elements), Records.
Iteration and equality Iterator<T> (what a function with yield returns), IHashable<T> (Hash, Equals: dictionary keys), IComparable<T> (CompareTo), IToString. A type with an Iterator() method works in loop (x in c).
Errors Exception and the standard errors (see Errors).
Time DateTime (Now, UtcNow, Today), TimeSpan, DayOfWeek.
Program Environment (GetCommandLineArgs, GetEnvironmentVariable, ProcessorCount, TickCount64), GC, Resources (files built into the program).
Reflection Type (from typeof(T) or x.GetType()): fields, properties, methods, constructors, attributes, generic arguments; Activator; Attribute, FriendOfAttribute.
Exchange Exchange: packs strings and bytes to pass between code built with different memory modes.

System.IO

Types What they do
File Exists, ReadAllText, ReadAllLines, ReadAllBytes, WriteAllText, WriteAllBytes, Delete, GetLastWriteTime.
Directory Exists, CreateDirectory, GetFiles, GetEntries, Delete.
Path Combine, GetFileName, GetExtension, GetFileNameWithoutExtension, GetDirectoryName, ChangeExtension.
Stream, FileStream, MemoryStream, BufferedStream Byte streams, synchronous and asynchronous (ReadAsync, WriteAsync, CopyToAsync…).
StreamReader, StreamWriter, StringReader, StringWriter, TextReader, TextWriter Text over streams and strings, in UTF-8.
BinaryReader, BinaryWriter Numbers and strings in binary form.
IOError, EndOfStreamError What fails.

System.Text

Types What they do
JsonValue, JsonKind, JsonReader Parse JSON (JsonValue.Parse), read it (Get, At, AsString, AsNumber, AsBool, IsNull), and build it (NewObject().Set(…), NewArray().Add(…), ToString()).
Regex, Match Regular expressions: IsMatch, Match, Matches, Replace (with $1 groups).
Encoding, UTF8Encoding Encoding.UTF8.GetBytes(text) and GetString(bytes).

System.Net

Types What they do
TcpClient, TcpListener, NetworkStream TCP connections: TcpClient.Connect(host, port), listener.Accept().
HttpClient, HttpResponse HttpClient.Get(url).

System.Diagnostics

Types What they do
Process Process.Run(command) runs a command and gives its exit code; Process.Run(program, arguments) gives a ProcessResult with its output; Process.Start starts one and lets you read it.
Stopwatch Measures elapsed time.

System.Threading and System.Threading.Tasks

Types What they do
Thread A thread running a function: Start, Join, Thread.Sleep.
Mutex, Lock, Condition, SemaphoreSlim, CountdownEvent, ManualResetEvent, AutoResetEvent Synchronization.
AtomicI32, AtomicI64, AtomicBool, Interlocked Atomic operations.
ThreadPool, Parallel Parallel.For(from, to, i => …) and Parallel.Invoke(actions).
ConcurrentQueue<T>, BlockingCollection<T> Collections shared between threads.
Task, Task<T>, Scheduler What async functions return (see Async and reactive code).

System.Reactive

Source, Effect, Computed and Reactive (Reactive.Batch): what reactive, computed and effect are built on (see Async and reactive code).

System.Runtime.InteropServices

Types What they do
ImportAttribute, ExportAttribute Calling C functions, and being called from C.
Marshal, Memory, NativeMemory Native memory and strings.
ValueLayoutAttribute, FieldOffsetAttribute, Layout The exact layout of a value, for C structs and unions.

See Native bindings.

System.Bindings

A separate library, System.Bindings.dll, for binding profiles: BindingProfile, BindingSettings, BindingModel, CFunction, CStruct, CEnum, CConstant, NameCase, SplitBy.

¿Te resultó útil esta página?

No se guarda ninguna dirección; tu nombre de usuario sí, si iniciaste sesión.

Esc