C# (.NET) Class Library Quick
Reference
This quick reference lists useful classes and
other types that we will often use in Programming 2. See the official
API documentation for a complete reference.
All members in this reference are public unless
otherwise noted.
== Index of namespaces ==
System
-
Action
| Array | Boolean
| Char
|
Comparison
|
Console
| ConsoleColor |
DateTime
|
Double
| EventHandler | Exception
|
Func
|
IComparable
|
IDisposable
| Index |
Int32
| Int64
|
Math
| Object | Predicate
| Random | Range
|
String
(
formatting
)
|
TimeSpan
-
System.Collections.Generic
-
ICollection
| IDictionary
| IEnumerable |
IEnumerator
|
IList
| ISet |
KeyValuePair | List
|
PriorityQueue
|
Queue
| Stack
-
System.Diagnostics
-
Debug
-
System.IO
-
Path
| StreamReader | StreamWriter
-
System.Linq
-
Enumerable
-
System.Runtime.InteropServices
-
Marshal
-
System.Text
-
StringBuilder
-
System.Text.Json
-
System.Text.RegularExpressions
== Implicit namespaces ==
The namespaces System, System.Collections.Generic,
System.IO and System.Linq are automatically available in
console programs: you don't need to import them via a 'using'
statement.
However, these namespaces are not automatically
available on ReCodEx, so you
must import them a 'using' statement if you want your program to run
successfully on ReCodEx.
If you want to disable
these implicit namespaces in your project even when building on your
own machine, make this change to your .csproj file:
<ImplicitUsings>disable</ImplicitUsings>
== System namespace ==
Action
- delegate void Action<in T>(T obj);
-
A delegate type for a function that takes a single parameter and
does not return a value.
Array
- object
Clone ();
-
Create a shallow copy of an array. Typically you will use a type
cast to convert the returned value to a specific array type, i.e.
the type of the array that was copied.
-
int GetLength(int
dimension);
-
Return the length of an array in the given dimension. Dimensions are
numbered starting from 0.
-
static int
IndexOf<T>
(T[]
array, T
value);
-
Return the zero-based index at which a value first appears in an
array, or -1 if it is absent.
-
int Length { get;
}
-
Return the total number of elements in an array. This is the product
of the lengths of all dimensions.
-
Note that array elements are numbered starting with 0, so the length
is not itself a valid index.
-
int Rank { get;
}
-
Return the number of dimensions in an array.
-
static void Reverse<T> (T[] array);
-
Reverse the order of the elements in an array.
-
static void
Sort<T> (T[] array);
static
void
Sort<T> (T[] array, Comparison<T> comparison); -
Sort an array. The first form orders
elements using each element's implementation
of
IComparable<T>
.
The second form uses the specified Comparison<T>
to order the elements.
bool
= Boolean : IComparable<Boolean>
- static
bool
Parse(string
s);
-
Parse a boolean from a string.
char =
Char : IComparable<Char>
A char
represents a
16-bit Unicode character.
- static
bool
IsDigit(char
c);
-
Return true if the given character is a digit.
-
static bool
IsLetter(char
c);
-
Return true if the given character is an uppercase or lowercase
letter.
-
static bool
IsWhiteSpace(char
c);
-
Return true if c is a whitespace character such as a space or
newline.
-
static char
ToLower(char
c);
-
Convert a character to lowercase.
-
string
ToString();
-
Convert a character to a string containing only that single
character.
-
static char
ToUpper (char
c);
-
Convert a character to uppercase.
Comparison<T>
- delegate
int
Comparison<in
T>(T x, T y);
-
A delegate type for a method that compares two objects of the same
type. The method should return
-
a negative value if x is less than y
-
0 if x equals y
-
a positive value if x is greater than y
Console
- static
ConsoleColor BackgroundColor { get;
set; }
-
Set the background color for console output.
-
static
ConsoleColor ForegroundColor { get;
set; }
-
Set the foreground color for console output.
-
static int
Read();
-
Read a character from standard input. Returns -1 if no more input is
available. If the return value is not -1, typically you will use a
type cast to convert it to a
char
:
int
i = Read();
if
(i != -
1
) {
char
c = (
char
) i;
…
-
When standard input is coming from the terminal (i.e. is not
redirected from a file), this method's behavior is
platform-dependent:
On Linux or macOS, this method will return as soon as a key is
pressed – it does not wait for the user to press Enter. In this
situation it will never return -1.
On Windows, this method will not return
until the user has entered an entire line of input. It may return
-1 if the user presses Ctrl+Z.
- static
ConsoleKeyInfo ReadKey();
-
static
ConsoleKeyInfo ReadKey(bool
noEcho);
-
Read a key from the keyboard. This method returns as soon as the
user has pressed any key.
-
Normally the key the user types will be echoed to the console. To
suppress this echo, pass
true
as the
value of the noEcho
parameter. -
Do not read input using ReadKey() when solving any ReCodEx
exercise. This method always reads from the keyboard, but when
your program runs on ReCodEx there is no keyboard, so the method
will fail. Instead, use
Read()
or
ReadLine()
to read from standard input. -
static string?
ReadLine();
-
Read a line from standard input. Returns
null
if no more input is available. -
static void
ResetColor ();
-
Reset the foreground and background colors to their default values.
-
static void
Write(char
value);
-
static void
Write(double
value);
-
static void
Write(int
value);
-
static void
Write(string
value);
-
Write a string or other value to standard output.
-
static void
WriteLine(char
value);
-
static void
WriteLine(double
value);
-
static void
WriteLine(int
value);
-
static void
WriteLine(string
value);
-
Write a string or other value to standard output, followed by a
newline.
ConsoleColor
An enumeration of possible colors for console
output. Some common values include Black
,
Blue
, Green
,
Red
, White
,
Yellow
.
DateTime
A DateTime
represents
an instance in time.
DateTime (int year, int
month, int day);
-
Construct a
DateTime
from a year,
month, and day. -
int Day { get; }
-
Return the day; this is a number between 1 and 31.
-
int Hour { get; }
-
Return the hour; this is a number between 0 and 23.
-
int Minute { get; }
-
Return the minute; this is a number between 0 and 59.
-
int Month { get; }
-
Return the month; this is a number between 1 and 12.
-
static DateTime
Now { get;
}
-
Return the current date/time.
-
long Ticks { get; }
-
Convert this DateTime to a number, specifically the number of
100-nanosecond intervals that have elapsed since midnight, January
1, year 1.
-
int Year { get; }
-
Return the year.
-
static TimeSpan
operator -
(DateTime d1, DateTime d2);
-
Return the span of time between two DateTime objects.
double
= Double : IComparable<Double>
A double
is a 64-bit
floating-point value.
- const
double
NaN;
-
A special value that is not a number.
-
const double
NegativeInfinity;
-
A special value that is less than any other
double
. -
static double
Parse(string
s);
-
Parse a
double
from a string. -
Warning: Depending
on your computer's locale settings, this method might expect a
string such as "3.5", or
it
might instead expect a string such as "3,5". To parse a
string that includes a decimal point "." in any locale,
call
using System.Globalization;
…
double d = double.Parse("3.5", CultureInfo.InvariantCulture);
-
const double
PositiveInfinity;
-
A special value that is greater than any other
double
. -
string
ToString();
-
Convert a
double
to a string. -
Warning: Depending on your computer's locale setting, this
method might produce a string such as "3.5", or it
might produce "3,5". To produce a string that includes a
decimal point "." in any locale, call
using System.Globalization;
…
string s = d.ToString(CultureInfo.InvariantCulture);
-
If you want to limit the number of digits after the decimal point,
use a format specifier:
string s = d.ToString("F2", CultureInfo.InvariantCulture);
-
static bool
TryParse (string
s, out
double
result);
-
Attempt to parse a
double
from a
string. Returns true if successful.
EventHandler
- delegate
void
EventHandler (object?
sender, EventArgs e);
-
A delegate type used for various kinds of event handlers, e.g. in
GTK.
Exception
- Exception ();
-
Construct an Exception.
-
Exception (string
message);
-
Construct an Exception with an error message.
-
string Message { get; }
-
A message describing this exception.
Func
- delegate
U Func<T, U>(T arg);
-
A delegate type for a function from a type T to a type U.
IComparable<in T>
Any object implementing the IComparable<T>
interface can be compared with objects of type T.
- int
CompareTo (T other);
-
Returns
a negative value if this object is less than
other
0 if this
object equals other
a positive
value if this object is greater than
other
IDisposable
An object implementing IDisposable
has resources that the caller should free when they are finished
using the object.
- void
Dispose ();
-
Release resources associated with this object.
Index
An object representing an index such as 2 or ^2.
- bool IsFromEnd { get; }
-
If true, this index is from the end (as in e.g.
^2
);
if false, it is from the start. -
int Value { get; }
-
The index value. For example, in the indices 2 and ^2 the value is
2.
int =
Int32 : IComparable<Int32>
An int
is a signed
32-bit integer.
- const
int
MaxValue = 2_147_483_647;
-
The largest value that can be stored in an
int
. -
const int
MinValue = -2_147_483_648;
-
The smallest value that can be stored in an
int
. -
static int
Parse(string
s);
-
Parse an integer from a string. Throws a
FormatException
if the string does not contain a valid integer. -
string
ToString();
-
Convert an integer to a string.
-
static bool
TryParse (string
s, out int
result);
-
Attempt to parse an integer from a string. Returns true if
successful.
long =
Int64 : IComparable<Int64>
A long
is a signed
64-bit integer.
- const
int
MaxValue = 9_223_372_036_854_775_807;
-
The largest value that can be stored in an
long
. -
const int
MinValue = -9_223_372_036_854_775_808;
-
The smallest value that can be stored in an
long
. -
static long
Parse(string
s);
-
Parse a
long
from a string. Throws a
FormatException
if the string does not
contain a valid integer. -
string
ToString();
-
Convert a
long
to a string. -
static bool
TryParse (string
s, out
long
result);
-
Attempt to parse a
long
from a string.
Returns true if successful.
Math
- static
int
Abs(int
value);
-
static double
Abs(double
value);
-
Return the absolute number of an integer or floating-point number.
-
static double
Acos(double
d);
-
Return the arccosine in radians of the given number.
-
static double
Asin(double
d);
-
Return the arcsine in radians of the given number.
-
static double
Atan2(double
y, double
x);
-
Return the arctangent in radians of the value (y / x). The returned
angle θ will be in the range -π ≤ θ ≤ π.
-
static double
Cos(double
d);
-
Return the cosine of the given angle in radians.
-
static double
Exp(double
d);
-
Return
the number e raised to the given power.
-
static double
Log(double
d);
-
Return the natural (base e) logarithm of a number.
-
static int
Max(int
val1, int
val2);
-
static double
Max(double
val1, double
val2);
-
Return the greater of two values.
-
static int
Min(int
val1, int
val2);
-
static double
Min(double
val1, double
val2);
-
Return the lesser of two values.
-
const double
PI = 3.14159265358979;
-
The constant π.
-
static double
Pow(double
x, double
y);
-
Return a number raised to a power.
-
static double
Round(double
a);
-
Round a floating-point number to the nearest integer. (Values of the
form i + 0.5 (for any integer i) are always rounded
towards an even number.)
-
static int
Sign(int
a);
-
static int
Sign(double
a);
-
Return the sign of a,
which is +1, 0, or -1 in the cases where a > 0, a = 0 or a <
0, respectively.
-
static double
Sin(double
a);
-
Return the sine of the given angle in radians.
-
static double
Sqrt(double
d);
-
Return the square root of a floating-point number.
-
static double
Truncate(double
d);
-
Return the integer part of
d
,
which is always smaller than (or equal to) d
in
absolute value.
object = Object
The Object
class is
the top of the class hierarchy. All types inherit directly or
indirectly from Object
.
- virtual
bool
Equals (object?
obj);
-
Return true if this object is equal to
obj
.
By default, for reference types this method tests reference
equality: it returns true if this object and obj
are actually the same object. -
virtual int
GetHashCode ();
-
Return a hash code for this object. If you override
Equals
,
you must also override this method and ensure that equal values will
always have the same hash code. -
protected object
MemberwiseClone
();
-
Return a shallow copy of this object.
-
virtual string
ToString ();
-
Convert this object to a string.
Predicate
- delegate
bool
Predicate<in
T>(T obj);
-
A delegate type for a predicate (i.e. a
boolean condition) on objects of type T.
Random
A pseudo-random number generator.
- Random();
-
Create a new random number generator using a seed value derived from
the current time.
-
Random(int
seed);
-
Create a random number generator with the given seed value.
-
int Next(int
maxValue);
-
Return a random integer from 0 to (
maxValue
– 1). -
double
NextDouble();
-
Return a random double in the range [0.0, 1.0).
Range
An object representing a range such as 5..10
,
5..
or ..10
.
- Index End { get; }
-
An Index representing the (exclusive) end of the range. If the range
has no explicit end, this will be an Index with IsFromEnd = true and
Value = 0.
-
Index Start { get; }
-
An Index representing the (inclusive) start of the range. If the
range has no explicit start, this will be an Index with IsFromEnd =
false and Value = 0.
string
= String : IComparable<String>
- String(char[]
value);
-
Construct a string from an array of characters.
-
String(char
c, int
count);
-
Construct a string that contains the character
c
repeated count
times. -
bool
Contains(char
c);
-
Return true if this string contains the character c.
-
int IndexOf(char
c);
-
Return the index of the first occurrence of character c in this
string, or -1 if none.
-
int
IndexOfAny(char[]
anyOf);
-
Return the index of the first occurrence of any of the given
characters, or -1 if none.
-
static string
Join(string
separator, params
string[]
a);
static
string
Join<T>(string
separator, IEnumerable<T> a); -
Concatenate the strings or other values in the enumerable
a
,
placing the given separator string between each pair. The values in
the enumerable a will be converted to strings if necessary. -
int Length { get;
}
-
Return the length of a string.
-
string Remove(int
startIndex, int
count);
-
Return a copy of the string in which
count
characters starting at position startIndex
have been deleted. -
string
Replace(string
oldValue, string
newValue);
-
Return a copy of the string in which
all occurrences of
oldValue
have been
replaced with newValue
. -
string[]
Split(params
char[]
separators);
-
Split a string into substrings delimited by any of the given
characters. If no separators are specified, all whitespace
characters are delimiters.
-
Be warned that
Split
will return empty
strings if there are repeated delimiters, or if delimiters
appear at the beginning or end of the string, or if the
string is empty. For example,
"a b".Split()
=> {
"a", "b" }
"a b".Split()
=> { "a", "", "b"
}
"
a b ".Split() => { "", "a", "b",
"" }
"
".Split() => { "", "" }
"".Split()
=> { "" }
- bool
StartsWith(string
prefix);
-
Return true if this string starts with
prefix
. -
string
Substring(int
startIndex);
-
Return a substring containing all characters from
startIndex
through the end of the string. -
string
Substring(int
startIndex, int
length);
-
Return a substring of
length
characters
starting at position startIndex
. -
char[]
ToCharArray();
-
Convert a string to an array of characters.
-
string ToLower();
-
Convert a string to lowercase.
-
string ToUpper();
-
Convert a string to uppercase.
-
string Trim();
-
Remove all leading and trailing whitespace from a string.
string formatting
A formatted string such as $"the
sum is {x + y}"
can contain interpolated values
surrounded in braces. Each interpolated value may be followed by a
colon and a format code. Common format
codes include
d – an integer
in decimal (base 10). This format code may be followed by an
integer, which indicates the total number of digits to print. If it
is specified, the result will be padded with 0 digits on the left as
necessary.
f – a
floating-point number in fixed-point (i.e. not exponential)
notation. This
format code may be followed by an integer, which indicates how many
digits should appear after
the decimal point.
n – a number
with separator characters, producing a string such as
"223,566,221.225". This
format code may be followed by an integer, which indicates how many
digits should appear after
the decimal point.
x – an integer
in hexadecimal (base 16)
TimeSpan
A TimeSpan represents a time interval.
- TimeSpan (int days, int hours, int minutes, int
seconds);
-
Construct a
TimeSpan
representing the
given number of days, hours, minutes, and seconds. -
double
TotalMilliseconds { get;
}
-
Return the total number of milliseconds in this
TimeSpan
.
==
System.Collections.Generic namespace ==
overview
HashSet<T> : ISet<T>
A set implemented using a hash table.
- HashSet<T>();
-
Create an empty HashSet.
-
HashSet<T>(IEnumerable<T> collection);
-
Create a HashSet initialized with elements from the given
collection.
ICollection<T>
: IEnumerable<T>
ICollection<T>
contains methods implemented by many collection classes.
- void
Add (T item);
-
Add an item to a collection.
-
void Clear ();
-
Remove all items from a collection.
-
bool Contains (T
item);
-
Return true if the collection contains the given item.
-
int Count { get;
}
-
Return the number of items in a collection.
-
bool Remove (T
item);
-
Remove the first occurrence of the given element, if any. Returns
false if the item was not present in the collection.
IDictionary<K, V> : ICollection<KeyValuePair<K, V>>
An IDictionary<K, V>
is a dictionary (also known as a map or associative array).
- V this[K
key] { get;
set; }
-
Get or set the item with the given key. When retrieving, throws a
KeyNotFoundException
if no item with
the key is present. -
bool ContainsKey
(K key);
-
Return true if an item with the given key is present.
-
ICollection<K> Keys { get;
}
-
Get a collection of all keys in the dictionary.
-
bool Remove (K
key);
-
Remove the item with the specified key, if any. Returns true if an
item was removed, false if the key was not found.
-
bool TryGetValue
(TKey key,
out TValue
value);
-
If the given key is in the dictionary, place its value in
value
and return true; otherwise return false. -
ICollection<V> Values { get;
}
-
Get a collection of all values in the dictionary.
IEnumerable<out T>
The foreach
statement
can iterate over any object that implements IEnumerable<T>
.
An iterator (a method that returns values using
'yield return') may have return type IEnumerable<T>.
The System.Linq namespace includes many extension
methods for this interface.
- IEnumerator<out T> GetEnumerator ();
-
Return an enumerator over the object's values.
IEnumerator<out
T> : IDisposable
An IEnumerator<T> produces a series of
values.
An iterator (a method that returns values using
'yield return') may have return type IEnumerator<T>.
- T Current { get; }
-
Return the current value in the enumeration.
-
bool MoveNext();
-
Move to the next value in the enumeration.
IList<T>
: ICollection<T>
An IList<T>
is
a dynamic array. See the concrete implementation List<T>
below.
- T this[int
index] { get;
set; }
-
Get or set the element at the given index. Will throw an exception
if the index is out of bounds.
-
int IndexOf (T
item);
-
Return the index of the given item, or -1 if not present.
-
void Insert (int
index, T item);
-
Insert an item at a given index.
-
void RemoveAt
(int
index);
-
Remove the item at a given index.
ISet<T>
: ICollection<T>
An ISet<T>
is a
dynamic set.
- void
IntersectWith (IEnumerable<T> other);
-
Modify this set to contain only elements that are also in
other
. -
bool SetEquals
(IEnumerable<T> other);
-
Return true if this set contains the same elements as the given
collection.
-
void UnionWith
(IEnumerable<T> other);
-
Modify this set to contain elements that are in the current set, in
other
, or in both.
KeyValuePair<K, V>
An IDictionary
is a
collection of KeyValuePair
objects.
- KeyValuePair (K key, V value);
-
Construct a KeyValuePair.
-
K Key { get;
}
-
Get the key in a key/value pair.
-
V Value { get;
}
-
Get the value in a key/value pair.
List<T> :
IList<T>
A List<T>
is a
dynamic array. It has the methods below, and also inherits methods
from IList<T>
(see above).
- List ();
-
Construct an empty List.
-
List (IEnumerable<T> e);
-
Construct a List containing elements copied from the given
IEnumerable
. -
void AddRange(IEnumerable<T> collection);
-
Add all elements in the given collection to the end of this list.
-
bool Exists (Predicate<T> p);
-
Return true if p is true for any element in the list.
-
List<T> FindAll (Predicate<T> p);
-
Return a list of all elements for which p is true.
-
void Reverse ();
-
Reverse the order of the elements in a list.
-
void Sort ();
void Sort (Comparison<T> comparison); -
Sort a list's elements. The first form above uses the default
comparer, which will use the elements' IComparable<T>
interface if available. The second form uses a Comparison<T>
(a delegate type).
-
T[] ToArray ();
-
Convert a list to an array.
PriorityQueue<TElem,
TPrio>
A priority queue of items that have a value (of
type TElem) and a priority (of type TPrio). The Dequeue operation
removes the item with the smallest priority. This class is
implemented using a min-heap.
- PriorityQueue ();
-
Create an empty priority queue.
-
int Count { get; }
-
Return the number of elements in the queue.
-
TElement Dequeue ();
-
Remove and return the element with lowest priority. This method does
not return the element's priority. If the queue is empty, the method
throws an InvalidOperationException.
-
void Enqueue (TElem element, TPrio priority);
-
Enqueue an element with its priority.
-
bool TryDequeue (out TElem element, out TPrio priority);
-
If the queue is non-empty, remove the element with lowest priority
and return true. The
out
parameters
will receive the element and its priority. If the queue is empty,
return false.
Queue<T>
: IEnumerable<T>
A Queue<T>
is
an array-based queue.
- int
Count { get;
}
-
Return the number of items in a queue.
-
T Dequeue ();
-
Remove an element from the beginning of a queue. If the queue is
empty, an InvalidOperationException will be thrown.
-
void Enqueue (T
item);
-
Add an element to the end of a queue.
-
bool TryDequeue (out T result);
-
If the queue is non-empty, dequeue a value into
result
and return true; otherwise return false.
SortedSet<T> : ISet<T>
A SortedSet<T> is a set implemented using a
balanced binary tree.
- SortedSet<T>();
-
Create an empty SortedSet.
-
SortedSet<T>(IEnumerable<T> collection);
-
Create a SortedSet initialized with elements from the given
collection.
-
T Max { get; }
-
Return the maximum value in the set. If the set is empty, return the
default value of type T.
-
T Min { get; }
-
Return the minumum value in the set. If the set is empty, return the
default value of type T.
Stack<T>
: IEnumerable<T>
A Stack<T>
is
an array-based stack.
- int
Count { get;
}
-
Return the number of items on a stack.
-
T Pop ();
-
Pop an item from the top of a stack. If the stack is empty, an
InvalidOperationException will be thrown.
-
void Push (T
item);
-
Push an item onto a stack.
-
bool TryPop (out T result);
-
If the stack is non-empty, pop a value into
result
and return true; otherwise return false.
==
System.Diagnostics namespace ==
Debug
- static
void
Assert
(bool
condition);
-
If the given condition is false, print an error message and exit the
program.
-
static void
Assert
(bool
condition,
string?
message);
-
If the given condition is false, print the given message and exit
the program.
== System.IO
namespace ==
Path
- static
string
Combine
(string
path1,
string
path2);
-
Combine two strings into a path, inserting a directory separator
character. For example,
Path.Combine("/home/joe",
"image.png")
will return "/home/joe/image.png"
on a Linux or macOS system, where the separator character is '/'. -
static string
GetExtension (string
path);
-
Return a path's extension. For
example,
Path.Get
Extension
("/home/joe/image.png")
returns ".png".
-
static string
GetFileName (string
path);
-
Return a path's filename. For example,
Path.GetFileName("/home/joe/image.png")
returns "image.png".
-
static string
GetFileNameWithoutExtension (string
path);
-
Return a path's filename without the extension. For example,
Path.GetFileNameWithoutExtension("/home/joe/image.png")
returns "image".
StreamReader : IDisposable
- StreamReader(string
path);
-
Open a file for reading. The file is assumed to use the UTF-8
encoding. Throws a FileNotFoundException if the file can't be found,
or a DirectoryNotFoundException if the path is invalid.
-
void Close();
-
Close a reader and release any associated resources.
-
bool EndOfStream
{ get; }
-
Return true if we have reached the end of the input data.
-
int Read();
-
Read a single character and return its character code. Returns -1 at
end of data.
-
If the return value is not -1, typically you will use a type cast to
convert it to a
char
:
StreamReader reader =
new
StreamReader(
"input_file"
);
int
i = reader.Read();
if
(i != -
1
) {
char
c = (
char
) i;
…
-
string?
ReadLine();
-
Read a line. Returns
null
at end of
data. -
string ReadToEnd ();
-
Read the rest of the input and return it as a single string.
StreamWriter : IDisposable
- StreamWriter(string
path);
-
Open a file for writing. The file will be written in UTF-8 encoding.
Throws a DirectoryNotFoundException if the path is invalid.
-
Important: You must call the
Close()
method to close the file when you are done writing. If you don't do
this, some or all output may not actually be written to the file! -
void Close();
-
Close a writer and release any associated resources.
-
void
WriteLine(string
value);
-
Write a string, followed by a newline.
== System.Linq
namespace ==
Enumerable
- static IEnumerable<T> Empty<T> ();
-
Return an empty enumeration.
-
static
IEnumerable<int>
Range (int
start, int
count);
-
Generate an enumeration of
count
integers beginning at start
.
IEnumerable<T>
extension methods
- bool
All<T>(Func<T,bool>
cond);
-
Return true if the given condition is true for all elements in this
sequence.
-
bool
Any<T>(Func<T,bool>
cond);
-
Return true if the given condition is true for any elements in this
sequence.
-
IEnumerable<T> Append<T>(T element);
-
Append an element to a sequence.
-
IEnumerable<T> Concat<T>(IEnumerable<T> second);
-
Concatenate two sequences.
-
bool
Contains<T>(T
element);
-
Return true if this sequence contains the given element.
-
int Count<T>();
-
Return the number of elements in a sequence.
-
int
Count<T>(Func<T, bool>
cond);
-
Return the number of elements in a sequence where a given condition
is true.
-
T First<T>();
-
Return the first element of a sequence.
-
T Max<T>();
-
Return the maximum value in a sequence. If the sequence is empty,
returns a default value of type T.
-
T? MaxBy<T,U> (Func<T,U> f);
-
Given an sequence of values of type T, return the value x for which
f(x) is the greatest, or null if the sequence is empty.
-
T Min<T>();
-
Return the minumum value in a sequence. If the sequence is empty,
returns a default value of type T.
-
T? MinBy<T,U> (Func<T,U> f);
-
Given an sequence of values of type T, return the value x for which
f(x) is the smallest, or null if the sequence is empty.
-
IEnumerable<T> OrderBy<T,K>(Func<T,K>
f);
-
Given an sequence of values of type T and a key selector function f,
sort the values by their keys.
-
IEnumerable<T>
OrderByDescending<T,K>(Func<T,K> f);
-
Given an sequence of values of type T and a key selector function f,
sort the values by their keys in descending order.
-
IEnumerable<T> Prepend<T>(T element);
-
Prepend an element to a sequence.
-
IEnumerable<T> Reverse<T>();
-
Reverse a sequence.
-
IEnumerable<U> Select<T, U>(Func<T, U> f);
-
Map the given function over this sequence. (Traditionally this
higher-order function is called
map
.) -
IEnumerable<U> SelectMany<T, U>(Func<T,
IEnumerable<U> f);
-
Map the given function over this sequence and concatenate the
results into a single sequence.
-
bool
SequenceEqual<T>(IEnumerable<T> e);
-
Return true if this sequence is identical to the sequence e, i.e. it
contains the same elements in the same order.
-
int Sum ();
-
Compute
the sum of a sequence of integers.
-
IEnumerable<T> Take<T>(int
count);
-
Take elements from this sequence until either the sequence ends or
count
elements have been reached. -
IEnumerable<T> TakeWhile<T>(Predicate<T> cond);
-
Take elements from this sequence only for as long as the given
condition is true.
-
T[] ToArray<T>();
-
Convert an enumeration to an array.
-
List<T> ToList<T>();
-
Convert an enumeration to a list.
-
IEnumerable<T> Where<T>(Predicate<T> cond);
-
Filter this sequence, keeping only elements where
cond
is true. (Traditionally this higher-order function is called
'filter'.)
==
System.Runtime.InteropServices namespace ==
Marshal
- static void Copy (IntPtr source, byte[]
destination, int startIndex, int length);
-
Copy data from unmanaged memory (i.e.
memory not managed by the C#/CLR
runtime) to a C# array.
-
static void Copy (byte[] source, int startIndex, IntPtr destination,
int length);
-
Copy data from a C# array to unmanaged memory.
== System.Text
namespace ==
StringBuilder
- A
StringBuilder
is
used for building a string incrementally. You can append a series of
strings to a StringBuilder
, then
convert the result to a string by calling its ToString
method. For large strings, this will be much faster than using
string concatenation to build a string. -
StringBuilder ();
-
Create an empty
StringBuilder
. -
StringBuilder
Append(
char
c);
-
Append a
char
to this StringBuilder
.
(The same StringBuilder
is returned
from the method.) -
StringBuilder
Append(
string
s);
-
Append a string to this
StringBuilder
.
(The same StringBuilder
is returned
from the method.) -
StringBuilder Clear();
-
Reset this
StringBuilder
to the empty
string. (The same StringBuilder
is
returned from the method.)
==
System.Text.Json namespace ==
JsonDocument
A document in JSON format.
- static JsonDocument Parse (string json);
-
Parse JSON from a string into a
JsonDocument
. -
JsonElement RootElement { get; }
-
The root element of the document.
-
virtual string ToString();
-
Convert a
JsonDocument
to a string in
JSON format.
JsonElement
A JSON element.
- JsonElement this[int index] { get; }
-
Retrieve an indexed value from an element whose kind is
Array
. -
int GetInt32 ();
-
Retrieve the integer value of an element whose kind is
Number
. -
JsonElement GetProperty (string propertyName);
-
Retrieve an indexed value from an element whose kind is
Object
. -
string? GetString ();
-
Retrieve the string value of an element whose kind is
String
. -
JsonValueKind ValueKind { get; }
-
The kind of this element.
JsonSerializer
- static T? Deserialize<T> (string json,
JsonSerializerOptions? options = default);
-
Deserialize a JSON string to an object.
-
static string Serialize<T> (T value, JsonSerializerOptions?
options = default);
-
Serialize an object to a string in JSON format.
JsonSerializerOptions
Options that can be used with JsonSerializer
.
- bool IncludeFields { get; set; }
-
Indicates whether fields are serialized. The default is false (i.e.
only public properties are serialized).
JsonValueKind
An enumeration representing a kind of JSON
element. Values include Number
, False
,
True
, String
,
Array
, Object
,
Null
.
== System.Text.RegularExpressions namespace ==
This namespace contains classes that can match
regular expressions in strings. See the regular
expression syntax summary.
Group
A group that was matched.
- int Index { get; }
-
The position in the input string where the match occurred.
-
string Value { get; }
-
The string that was matched.
GroupCollection : IEnumerable<Group>
A collection of groups in a single match.
- Group this[int groupnum] { get; }
-
An indexer that returns a single group by its integer index. Groups
appearing in the regular expression are indexed from 1. (this[0]
returns a Group representing the entire match.)
Match
A Match represents a single match of a regular
expression.
- GroupCollection Groups { get; }
-
Return all groups in the match.
-
int Index { get; }
-
The position in the input string where the match occurred.
-
Match NextMatch();
-
Return a new Match object with results for the next match in the
input string.
-
bool Success { get; }
-
True if this was a successful match.
-
string Value { get; }
-
The string that was matched.
MatchCollection : IEnumerable<Match>
A collection of matches of a regular expression
pattern.
- public int Count { get; }
-
The number of matches.
-
Match this[int i] { get; }
-
An indexer that returns a single match by its integer index.
Regex
- static bool IsMatch (string input, string
pattern);
-
Return true if the input string contains a match for the given
pattern.
-
static Match Match (string input, string pattern);
-
Return a Match object representing the first match of the given
pattern in the input string. If no matches are found, return a Match
object whose Success property is false.
-
static MatchCollection Matches (string input, string pattern);
-
Return a MatchCollection object representing all matches of the
given pattern in the input string.
-
static string Replace (string input, string pattern, string
replacement);
-
Return a copy of the input string in which all matches of the given
pattern have been replaced by the given replacement string.