Top 10 most commonly used .NET classes
Here’s a breakdown of the Top 10 most commonly used .NET classes (mainly from the System namespace) — with short, clear examples.
🧩 1. System.String
Used to represent and manipulate text.
string name = "Sagar";
string greeting = $"Hello, {name.ToUpper()}!";
Console.WriteLine(greeting); // Hello, SAGAR!
✅ Common methods:
Substring(), Replace(), Split(), Contains(), StartsWith(), Trim()
⚙️ 2. System.Console
Used for input/output in console apps.
Console.Write("Enter name: ");
string name = Console.ReadLine();
Console.WriteLine("Welcome, " + name);
✅ Common methods:
Write(), WriteLine(), ReadLine(), ReadKey()
🧮 3. System.Math
Contains mathematical constants and functions.
double radius = 3.5;
double area = Math.PI * Math.Pow(radius, 2);
Console.WriteLine(area);
✅ Common methods:
Math.Abs(), Math.Max(), Math.Min(), Math.Sqrt(), Math.Round()
📅 4. System.DateTime
Represents dates and times.
DateTime now = DateTime.Now;
Console.WriteLine("Today: " + now.ToShortDateString());
DateTime future = now.AddDays(10);
Console.WriteLine("After 10 days: " + future);
✅ Common methods:
AddDays(), AddMonths(), Subtract(), ToString()
📦 5. System.Collections.Generic.List<T>
Represents a dynamic array.
List<string> fruits = new List<string> { "Apple", "Banana" };
fruits.Add("Cherry");
foreach (var fruit in fruits)
Console.WriteLine(fruit);
✅ Common methods:
Add(), Remove(), Sort(), Contains(), Find()
🔑 6. System.Collections.Generic.Dictionary<TKey, TValue>
Stores key–value pairs.
var capitals = new Dictionary<string, string>
{
{"USA", "Washington"},
{"India", "New Delhi"}
};
Console.WriteLine(capitals["India"]); // New Delhi
✅ Common methods:
Add(), TryGetValue(), ContainsKey(), Remove()
⚡ 7. System.Threading.Tasks.Task
Represents asynchronous operations.
async Task<int> FetchDataAsync()
{
await Task.Delay(1000); // simulate delay
return 42;
}
int result = await FetchDataAsync();
Console.WriteLine(result);
✅ Common methods:
Run(), Wait(), Result, ContinueWith()
🧠 8. System.IO.File
Used to read/write files.
string path = "example.txt";
File.WriteAllText(path, "Hello .NET!");
string content = File.ReadAllText(path);
Console.WriteLine(content);
✅ Common methods:
ReadAllText(), WriteAllText(), AppendAllText(), Exists(), Delete()
🧮 9. System.Linq.Enumerable
Provides LINQ query extensions.
var numbers = new List<int> { 1, 2, 3, 4, 5 };
var even = numbers.Where(n => n % 2 == 0).ToList();
Console.WriteLine(string.Join(", ", even)); // 2, 4
✅ Common methods:
Where(), Select(), OrderBy(), Sum(), Count()
🧾 10. System.Exception
Base class for all exceptions.
try
{
int x = 10 / 0;
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
✅ Common derived classes:
IOException, ArgumentException, NullReferenceException, InvalidOperationException
💡 Bonus (Also Commonly Used)
System.Random→ generates random numbersSystem.Text.StringBuilder→ efficient string manipulationSystem.Guid→ generate unique identifiersSystem.Linq.Queryable→ LINQ to Entities or LINQ to SQL