1. Email Validation using Regex (C#)
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string email = "[email protected]"; // Change this to test
string pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
Regex regex = new Regex(pattern);
if (regex.IsMatch(email))
{
Console.WriteLine("Valid Email");
}
else
{
Console.WriteLine("Invalid Email");
}
}
}
Explanation
The
Regexpattern matches common email formats like[email protected].
2. Password Strength Checker (C#)
A strong password typically contains:
At least one uppercase letter
At least one lowercase letter
At least one digit
At least one special character
A minimum length of 8 characters
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string password = "StrongP@ssw0rd"; // Change this to test
if (IsStrongPassword(password))
{
Console.WriteLine("Strong Password");
}
else
{
Console.WriteLine("Weak Password");
}
}
public static bool IsStrongPassword(string password)
{
if (password.Length < 8)
return false;
bool hasUpperCase = Regex.IsMatch(password, @"[A-Z]");
bool hasLowerCase = Regex.IsMatch(password, @"[a-z]");
bool hasDigit = Regex.IsMatch(password, @"\d");
bool hasSpecialChar = Regex.IsMatch(password, @"[\W_]");
return hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar;
}
}
3. Find Day of the Week from Given Date (C#)
using System;
public class Program
{
public static void Main()
{
DateTime date = new DateTime(2025, 11, 06); // Change this to test
Console.WriteLine("Day of the Week: " + date.DayOfWeek);
}
}
Explanation
The
DateTime.DayOfWeekproperty gives the day of the week from a given date.
4. Compound Interest Calculation (C#)
Formula
[
A = P \left(1 + \frac{r}{n}\right)^{nt}
]
Where
( A ) is the amount of money accumulated after ( t ) years, including interest.
( P ) is the principal amount.
( r ) is the annual interest rate (decimal).
( n ) is the number of times that interest is compounded per year.
( t ) is the time the money is invested for, in years.
using System;
public class Program
{
public static void Main()
{
double principal = 1000; // Initial amount
double rate = 0.05; // 5% interest
int timesCompounded = 4; // Quarterly
int years = 5; // 5 years
double compoundInterest = CalculateCompoundInterest(principal, rate, timesCompounded, years);
Console.WriteLine($"Compound Interest: {compoundInterest:C}");
}
public static double CalculateCompoundInterest(double principal, double rate, int n, int t)
{
return principal * Math.Pow((1 + rate / n), n * t) - principal;
}
}

Join the conversation! Your thoughts help the community grow.