csharp-methods / csharp_methods.csv
wingmanllc's picture
Upload the csharp methods csv
86a18b0 verified
Raw History Blame Contribute Delete
18.7 kB
"id","category","type","method","signature","returns","description","example"
"1","String","string","Length","int Length { get; }","int","Number of characters in the string.","int n = ""hello"".Length; // 5"
"2","String","string","Substring","string Substring(int startIndex, int length)","string","Returns part of a string.","""hello"".Substring(1, 3); // ""ell"""
"3","String","string","Split","string[] Split(char separator, StringSplitOptions options = None)","string[]","Splits a string into pieces on a separator.","""a,b,c"".Split(','); // [""a"",""b"",""c""]"
"4","String","string","Join","static string Join(string separator, IEnumerable<string> values)","string","Joins items into one string with a separator.","string.Join("", "", new[]{""a"",""b""}); // ""a, b"""
"5","String","string","Replace","string Replace(string oldValue, string newValue)","string","Replaces all occurrences of a substring.","""cat"".Replace(""c"", ""b""); // ""bat"""
"6","String","string","Contains","bool Contains(string value)","bool","Checks whether a substring exists.","""hello"".Contains(""ell""); // true"
"7","String","string","StartsWith","bool StartsWith(string value)","bool","Checks if the string begins with a value.","""hello"".StartsWith(""he""); // true"
"8","String","string","EndsWith","bool EndsWith(string value)","bool","Checks if the string ends with a value.","""hello"".EndsWith(""lo""); // true"
"9","String","string","IndexOf","int IndexOf(string value)","int","Index of the first occurrence, or -1.","""hello"".IndexOf(""l""); // 2"
"10","String","string","ToUpper","string ToUpper()","string","Converts to uppercase.","""hi"".ToUpper(); // ""HI"""
"11","String","string","ToLower","string ToLower()","string","Converts to lowercase.","""HI"".ToLower(); // ""hi"""
"12","String","string","Trim","string Trim()","string","Removes whitespace from both ends.",""" hi "".Trim(); // ""hi"""
"13","String","string","PadLeft","string PadLeft(int totalWidth, char paddingChar)","string","Pads the start to a total width.","""7"".PadLeft(3, '0'); // ""007"""
"14","String","string","IsNullOrEmpty","static bool IsNullOrEmpty(string? value)","bool","True if null or an empty string.","string.IsNullOrEmpty(""""); // true"
"15","String","string","IsNullOrWhiteSpace","static bool IsNullOrWhiteSpace(string? value)","bool","True if null, empty, or only whitespace.","string.IsNullOrWhiteSpace("" ""); // true"
"16","String","string","Format","static string Format(string format, params object[] args)","string","Builds a string from a format template.","string.Format(""{0} is {1}"", ""Ann"", 30);"
"17","String","string","Compare","static int Compare(string a, string b, StringComparison cmp)","int","Compares two strings; 0 means equal.","string.Compare(""a"", ""A"", StringComparison.OrdinalIgnoreCase); // 0"
"18","String","string","Equals","bool Equals(string value, StringComparison cmp)","bool","Compares strings with a chosen comparison.","""a"".Equals(""A"", StringComparison.OrdinalIgnoreCase); // true"
"19","String","StringBuilder","Append","StringBuilder Append(string value)","StringBuilder","Adds text to the end efficiently.","var sb = new StringBuilder(); sb.Append(""hi"");"
"20","String","StringBuilder","ToString","string ToString()","string","Converts the builder to a string.","string s = sb.ToString();"
"21","Math","Math","Max","static int Max(int a, int b)","int","Larger of two numbers.","Math.Max(3, 7); // 7"
"22","Math","Math","Min","static int Min(int a, int b)","int","Smaller of two numbers.","Math.Min(3, 7); // 3"
"23","Math","Math","Abs","static int Abs(int value)","int","Absolute value.","Math.Abs(-5); // 5"
"24","Math","Math","Pow","static double Pow(double x, double y)","double","Raises x to the power y.","Math.Pow(2, 3); // 8"
"25","Math","Math","Sqrt","static double Sqrt(double d)","double","Square root.","Math.Sqrt(16); // 4"
"26","Math","Math","Round","static double Round(double value, int digits)","double","Rounds to a number of decimals.","Math.Round(3.14159, 2); // 3.14"
"27","Math","Math","Floor","static double Floor(double d)","double","Rounds down to a whole number.","Math.Floor(3.9); // 3"
"28","Math","Math","Ceiling","static double Ceiling(double d)","double","Rounds up to a whole number.","Math.Ceiling(3.1); // 4"
"29","Math","Random","Next","int Next(int minValue, int maxValue)","int","Random int from min (inclusive) to max (exclusive).","new Random().Next(1, 7); // dice roll"
"30","Conversion","int","Parse","static int Parse(string s)","int","Converts text to int; throws on bad input.","int.Parse(""42"");"
"31","Conversion","int","TryParse","static bool TryParse(string s, out int result)","bool","Tries to convert text to int without throwing.","if (int.TryParse(""42"", out int n)) { }"
"32","Conversion","Convert","ToInt32","static int ToInt32(object value)","int","Converts many types to int.","Convert.ToInt32(""42"");"
"33","Conversion","Convert","ToString","static string ToString(int value)","string","Converts a value to string.","Convert.ToString(42);"
"34","Conversion","object","ToString","string ToString()","string","Text representation of any object.","42.ToString(""N0"");"
"35","Conversion","double","TryParse","static bool TryParse(string s, IFormatProvider p, out double result)","bool","Tries to parse a double using a culture.","double.TryParse(""3.5"", CultureInfo.InvariantCulture, out var d);"
"36","Collections","List<T>","Add","void Add(T item)","void","Adds an item to the end.","list.Add(5);"
"37","Collections","List<T>","AddRange","void AddRange(IEnumerable<T> items)","void","Adds many items at once.","list.AddRange(new[]{1,2,3});"
"38","Collections","List<T>","Remove","bool Remove(T item)","bool","Removes the first matching item.","list.Remove(5);"
"39","Collections","List<T>","RemoveAt","void RemoveAt(int index)","void","Removes the item at an index.","list.RemoveAt(0);"
"40","Collections","List<T>","RemoveAll","int RemoveAll(Predicate<T> match)","int","Removes all items matching a condition.","list.RemoveAll(x => x < 0);"
"41","Collections","List<T>","Insert","void Insert(int index, T item)","void","Inserts an item at an index.","list.Insert(0, 9);"
"42","Collections","List<T>","Contains","bool Contains(T item)","bool","Checks if an item is in the list.","list.Contains(5);"
"43","Collections","List<T>","IndexOf","int IndexOf(T item)","int","Index of an item, or -1.","list.IndexOf(5);"
"44","Collections","List<T>","Find","T? Find(Predicate<T> match)","T?","First item matching a condition.","list.Find(x => x > 3);"
"45","Collections","List<T>","FindAll","List<T> FindAll(Predicate<T> match)","List<T>","All items matching a condition.","list.FindAll(x => x > 3);"
"46","Collections","List<T>","Sort","void Sort()","void","Sorts the list in place.","list.Sort();"
"47","Collections","List<T>","Reverse","void Reverse()","void","Reverses the list in place.","list.Reverse();"
"48","Collections","List<T>","Clear","void Clear()","void","Removes all items.","list.Clear();"
"49","Collections","List<T>","Count","int Count { get; }","int","Number of items.","int n = list.Count;"
"50","Collections","List<T>","ToArray","T[] ToArray()","T[]","Copies the list into an array.","int[] arr = list.ToArray();"
"51","Collections","Array","Sort","static void Sort(Array array)","void","Sorts an array in place.","Array.Sort(arr);"
"52","Collections","Array","IndexOf","static int IndexOf(Array array, object value)","int","Index of a value in an array.","Array.IndexOf(arr, 3);"
"53","Collections","Array","Resize","static void Resize<T>(ref T[] array, int newSize)","void","Changes an array's size.","Array.Resize(ref arr, 10);"
"54","Collections","Dictionary<TKey,TValue>","Add","void Add(TKey key, TValue value)","void","Adds a key/value pair; throws if key exists.","dict.Add(""a"", 1);"
"55","Collections","Dictionary<TKey,TValue>","TryAdd","bool TryAdd(TKey key, TValue value)","bool","Adds only if the key is not present.","dict.TryAdd(""a"", 1);"
"56","Collections","Dictionary<TKey,TValue>","TryGetValue","bool TryGetValue(TKey key, out TValue value)","bool","Safely gets a value by key.","dict.TryGetValue(""a"", out var v);"
"57","Collections","Dictionary<TKey,TValue>","ContainsKey","bool ContainsKey(TKey key)","bool","Checks if a key exists.","dict.ContainsKey(""a"");"
"58","Collections","Dictionary<TKey,TValue>","Remove","bool Remove(TKey key)","bool","Removes an entry by key.","dict.Remove(""a"");"
"59","Collections","Dictionary<TKey,TValue>","Keys","KeyCollection Keys { get; }","KeyCollection","All keys.","foreach (var k in dict.Keys) { }"
"60","Collections","Dictionary<TKey,TValue>","Values","ValueCollection Values { get; }","ValueCollection","All values.","var total = dict.Values.Sum();"
"61","Collections","HashSet<T>","Add","bool Add(T item)","bool","Adds an item; false if already present.","set.Add(3);"
"62","Collections","HashSet<T>","UnionWith","void UnionWith(IEnumerable<T> other)","void","Adds all items from another collection.","set.UnionWith(other);"
"63","Collections","HashSet<T>","IntersectWith","void IntersectWith(IEnumerable<T> other)","void","Keeps only items also in another collection.","set.IntersectWith(other);"
"64","Collections","Queue<T>","Enqueue","void Enqueue(T item)","void","Adds an item to the back of the queue.","q.Enqueue(1);"
"65","Collections","Queue<T>","Dequeue","T Dequeue()","T","Removes and returns the front item.","int x = q.Dequeue();"
"66","Collections","Queue<T>","Peek","T Peek()","T","Returns the front item without removing it.","int x = q.Peek();"
"67","Collections","Stack<T>","Push","void Push(T item)","void","Adds an item to the top.","stack.Push(1);"
"68","Collections","Stack<T>","Pop","T Pop()","T","Removes and returns the top item.","int x = stack.Pop();"
"69","Collections","Stack<T>","Peek","T Peek()","T","Returns the top item without removing it.","int x = stack.Peek();"
"70","LINQ","Enumerable (LINQ)","Where","IEnumerable<T> Where(Func<T,bool> predicate)","IEnumerable<T>","Filters items by a condition.","nums.Where(n => n > 2);"
"71","LINQ","Enumerable (LINQ)","Select","IEnumerable<R> Select(Func<T,R> selector)","IEnumerable<R>","Transforms each item.","nums.Select(n => n * 2);"
"72","LINQ","Enumerable (LINQ)","OrderBy","IOrderedEnumerable<T> OrderBy(Func<T,K> key)","IOrderedEnumerable<T>","Sorts ascending by a key.","people.OrderBy(p => p.Name);"
"73","LINQ","Enumerable (LINQ)","OrderByDescending","IOrderedEnumerable<T> OrderByDescending(Func<T,K> key)","IOrderedEnumerable<T>","Sorts descending by a key.","people.OrderByDescending(p => p.Age);"
"74","LINQ","Enumerable (LINQ)","ThenBy","IOrderedEnumerable<T> ThenBy(Func<T,K> key)","IOrderedEnumerable<T>","Secondary sort after OrderBy.","people.OrderBy(p => p.Age).ThenBy(p => p.Name);"
"75","LINQ","Enumerable (LINQ)","GroupBy","IEnumerable<IGrouping<K,T>> GroupBy(Func<T,K> key)","IEnumerable<IGrouping<K,T>>","Groups items by a key.","people.GroupBy(p => p.City);"
"76","LINQ","Enumerable (LINQ)","First","T First(Func<T,bool> predicate)","T","First match; throws if none.","nums.First(n => n > 2);"
"77","LINQ","Enumerable (LINQ)","FirstOrDefault","T? FirstOrDefault(Func<T,bool> predicate)","T?","First match or default value.","nums.FirstOrDefault(n => n > 99);"
"78","LINQ","Enumerable (LINQ)","Single","T Single(Func<T,bool> predicate)","T","The only match; throws if zero or many.","users.Single(u => u.Id == 1);"
"79","LINQ","Enumerable (LINQ)","Any","bool Any(Func<T,bool> predicate)","bool","True if any item matches.","nums.Any(n => n > 2);"
"80","LINQ","Enumerable (LINQ)","All","bool All(Func<T,bool> predicate)","bool","True if every item matches.","nums.All(n => n > 0);"
"81","LINQ","Enumerable (LINQ)","Count","int Count(Func<T,bool> predicate)","int","Counts matching items.","nums.Count(n => n % 2 == 0);"
"82","LINQ","Enumerable (LINQ)","Sum","int Sum(Func<T,int> selector)","int","Adds up values.","orders.Sum(o => o.Total);"
"83","LINQ","Enumerable (LINQ)","Average","double Average(Func<T,int> selector)","double","Mean of values.","nums.Average();"
"84","LINQ","Enumerable (LINQ)","Max","T Max()","T","Largest value.","nums.Max();"
"85","LINQ","Enumerable (LINQ)","Min","T Min()","T","Smallest value.","nums.Min();"
"86","LINQ","Enumerable (LINQ)","Distinct","IEnumerable<T> Distinct()","IEnumerable<T>","Removes duplicates.","nums.Distinct();"
"87","LINQ","Enumerable (LINQ)","Take","IEnumerable<T> Take(int count)","IEnumerable<T>","First N items.","nums.Take(3);"
"88","LINQ","Enumerable (LINQ)","Skip","IEnumerable<T> Skip(int count)","IEnumerable<T>","Skips the first N items.","nums.Skip(2);"
"89","LINQ","Enumerable (LINQ)","ToList","List<T> ToList()","List<T>","Runs the query into a List.","var list = query.ToList();"
"90","LINQ","Enumerable (LINQ)","ToDictionary","Dictionary<K,V> ToDictionary(Func<T,K> key, Func<T,V> value)","Dictionary<K,V>","Builds a dictionary from items.","people.ToDictionary(p => p.Id, p => p.Name);"
"91","LINQ","Enumerable (LINQ)","Zip","IEnumerable<(T,U)> Zip(IEnumerable<U> second)","IEnumerable<(T,U)>","Pairs items from two sequences.","a.Zip(b);"
"92","LINQ","Enumerable (LINQ)","Concat","IEnumerable<T> Concat(IEnumerable<T> second)","IEnumerable<T>","Appends one sequence to another.","a.Concat(b);"
"93","LINQ","Enumerable (LINQ)","SelectMany","IEnumerable<R> SelectMany(Func<T,IEnumerable<R>> selector)","IEnumerable<R>","Flattens nested collections.","orders.SelectMany(o => o.Items);"
"94","DateTime","DateTime","Now","static DateTime Now { get; }","DateTime","Current local date and time.","var now = DateTime.Now;"
"95","DateTime","DateTime","UtcNow","static DateTime UtcNow { get; }","DateTime","Current UTC date and time.","var utc = DateTime.UtcNow;"
"96","DateTime","DateTime","AddDays","DateTime AddDays(double value)","DateTime","Returns a new date shifted by days.","DateTime.Today.AddDays(7);"
"97","DateTime","DateTime","ToString","string ToString(string format)","string","Formats a date as text.","now.ToString(""yyyy-MM-dd"");"
"98","DateTime","DateTime","TryParse","static bool TryParse(string s, out DateTime result)","bool","Tries to parse a date from text.","DateTime.TryParse(""2026-01-31"", out var dt);"
"99","DateTime","TimeSpan","TotalMinutes","double TotalMinutes { get; }","double","Length of a time span in minutes.","(end - start).TotalMinutes;"
"100","File IO","File","ReadAllText","static string ReadAllText(string path)","string","Reads an entire file as a string.","string text = File.ReadAllText(""a.txt"");"
"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();"