This cheat sheet provides an overview of essential C# array and string methods, including their functionalities such as searching, copying, sorting, and manipulating data. It also distinguishes between shallow and deep copies, highlights common beginner mistakes, and presents real use cases for practical application. Key methods include Array.IndexOf(), Array.Copy(), and string manipulation techniques like ToCharArray() and String.Join().
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views2 pages
CSharp_Array_Methods_CheatSheet
This cheat sheet provides an overview of essential C# array and string methods, including their functionalities such as searching, copying, sorting, and manipulating data. It also distinguishes between shallow and deep copies, highlights common beginner mistakes, and presents real use cases for practical application. Key methods include Array.IndexOf(), Array.Copy(), and string manipulation techniques like ToCharArray() and String.Join().
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
C# Array and String Methods Cheat Sheet
Array Methods
- Array.IndexOf(): Finds index of exact match (case-sensitive, only first match)
- Array.Copy(): Copies values (shallow copy for objects; size must be known) - Array.Sort(): Sorts array A-Z (modifies original, nulls come first) - Array.Reverse(): Reverses order (entire array only, copy before use) - Array.Clear(): Resets values to default (null/0), doesn't shrink array - Array.Find(): Finds first matching item with predicate - Array.Exists(): Checks if any item matches condition - Array.Resize(): Changes size with 'ref'; retains values - Clone(): Shallow copy (like Array.Copy)
String + Array Methods
- ToCharArray(): Converts string to char[] (for reversing/encrypting)
- Split(delimiter): Splits string into string[] (CSV/word parsing) - String.Join(): Joins array to string with delimiter - new string(char[]): Rebuilds string from char[]
Shallow vs Deep Copy
- Shallow Copy: Only references are copied (changes reflect in original)
- Deep Copy: Clone each object manually Example: copy[i] = new TaskItem { Title = original[i].Title, IsCompleted = original[i].IsCompleted };
Common Beginner Mistakes
- Sorting original: Always copy before sorting
- Split() for characters: Use ToCharArray instead - Clear() shrinks array: It does not; use Resize - Shared memory issues: Use deep copy for objects