id
int64
1
127
category
stringclasses
10 values
type
stringlengths
2
23
method
stringlengths
3
22
signature
stringlengths
7
68
returns
stringlengths
1
27
description
stringlengths
9
51
example
stringlengths
9
66
101
File IO
File
ReadAllLines
static string[] ReadAllLines(string path)
string[]
Reads every line of a file.
var lines = File.ReadAllLines("a.txt");
102
File IO
File
WriteAllText
static void WriteAllText(string path, string contents)
void
Writes text to a file, overwriting it.
File.WriteAllText("a.txt", "hi");
103
File IO
File
AppendAllText
static void AppendAllText(string path, string contents)
void
Adds text to the end of a file.
File.AppendAllText("a.txt", "more");
104
File IO
File
Exists
static bool Exists(string path)
bool
Checks if a file exists.
File.Exists("a.txt");
105
File IO
File
Delete
static void Delete(string path)
void
Deletes a file.
File.Delete("a.txt");
106
File IO
Directory
GetFiles
static string[] GetFiles(string path, string pattern)
string[]
Lists files matching a pattern.
Directory.GetFiles(".", "*.txt");
107
File IO
Path
Combine
static string Combine(string path1, string path2)
string
Joins path parts with the right separator.
Path.Combine("data", "a.txt");
108
File IO
Path
GetExtension
static string GetExtension(string path)
string
File extension including the dot.
Path.GetExtension("a.txt"); // ".txt"
109
File IO
JsonSerializer
Serialize
static string Serialize<T>(T value)
string
Converts an object to JSON.
JsonSerializer.Serialize(person);
110
File IO
JsonSerializer
Deserialize
static T? Deserialize<T>(string json)
T?
Converts JSON back to an object.
JsonSerializer.Deserialize<Person>(json);
111
Console
Console
WriteLine
static void WriteLine(string value)
void
Prints text and a new line.
Console.WriteLine("Hello");
112
Console
Console
Write
static void Write(string value)
void
Prints text without a new line.
Console.Write("Name: ");
113
Console
Console
ReadLine
static string? ReadLine()
string?
Reads a line typed by the user.
string? name = Console.ReadLine();
114
Console
Console
ReadKey
static ConsoleKeyInfo ReadKey()
ConsoleKeyInfo
Waits for a single key press.
Console.ReadKey();
115
Async
Task
Run
static Task Run(Action action)
Task
Runs work on a thread pool thread.
await Task.Run(() => Heavy());
116
Async
Task
Delay
static Task Delay(int milliseconds)
Task
Async wait without blocking a thread.
await Task.Delay(1000);
117
Async
Task
WhenAll
static Task WhenAll(IEnumerable<Task> tasks)
Task
Waits for all tasks to finish.
await Task.WhenAll(t1, t2);
118
Async
Task
WhenAny
static Task<Task> WhenAny(IEnumerable<Task> tasks)
Task<Task>
Completes when any task finishes.
await Task.WhenAny(t1, t2);
119
Async
HttpClient
GetStringAsync
Task<string> GetStringAsync(string url)
Task<string>
Downloads a URL as a string.
var html = await client.GetStringAsync(url);
120
Async
HttpClient
PostAsync
Task<HttpResponseMessage> PostAsync(string url, HttpContent content)
Task<HttpResponseMessage>
Sends an HTTP POST request.
await client.PostAsync(url, content);
121
Async
Thread
Sleep
static void Sleep(int milliseconds)
void
Blocks the current thread for a time.
Thread.Sleep(500);
122
Object
object
Equals
bool Equals(object? obj)
bool
Checks equality with another object.
a.Equals(b);
123
Object
object
GetType
Type GetType()
Type
The runtime type of an object.
obj.GetType().Name;
124
Object
object
GetHashCode
int GetHashCode()
int
Hash code used by dictionaries and sets.
obj.GetHashCode();
125
Object
Guid
NewGuid
static Guid NewGuid()
Guid
Creates a new unique identifier.
var id = Guid.NewGuid();
126
Object
Environment
GetEnvironmentVariable
static string? GetEnvironmentVariable(string name)
string?
Reads an environment variable.
Environment.GetEnvironmentVariable("PATH");
127
Object
GC
Collect
static void Collect()
void
Forces garbage collection (rarely needed).
GC.Collect();