This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Customer : INotifyPropertyChanged | |
{ | |
private string _firstName; | |
private string _lastName; | |
private DateOnly _birthDate; | |
public string FirstName | |
{ | |
get => _firstName; | |
set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CommonHelpers | |
{ | |
public static string GetSeason(int month) => $"The season is {month switch | |
{ | |
1 or 2 or 12 => "winter", | |
> 2 and < 6 => "spring", | |
> 5 and < 9 => "summer", | |
> 8 and < 12 => "autumn", | |
_ => "unknown.", | |
}}."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var paths = Environment.GetEnvironmentVariable("Path")!.Split(";"); | |
foreach (var (part, index) in paths.Select((part, index) => (value: part, i: index))) | |
{ | |
Console.WriteLine($"{index,-3}{part}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string firstLastName = "KarenPayne"; | |
var separated = firstLastName.SplitByCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; | |
static List<string> names = ["KaRen", "YelEna", "BiLL"]; | |
private static void CaseInsensitiveDictionary1() | |
{ | |
Dictionary<string, string> userDictionary = new(StringComparer.InvariantCultureIgnoreCase) | |
{ { "karen", "Developer advocate" }, { "yelena", "Manager" }, { "bill", "Web master" }, }; | |
foreach (var name in names) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StringExtensions | |
{ | |
public static string? FirstCharacterToLowerCase(this string? sender) | |
{ | |
if (!string.IsNullOrEmpty(sender) && char.IsUpper(sender[0])) | |
{ | |
return sender.Length == 1 ? | |
char.ToLower(sender[0]).ToString() : | |
$"{char.ToLower(sender[0])}{sender[1..]}"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Globalization; | |
using System.Text.RegularExpressions; | |
namespace ConsoleApp1; | |
internal partial class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var input = "Enter anything 12 and I will try 44 to detect any number (leave empty 1 to exit):"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string input = "There are 5 numbers in this string: 40, 30, and 10. 44"; | |
string[] numbers = Regex.Split(input, @"\D+"); | |
foreach (string value in numbers) | |
{ | |
if (string.IsNullOrEmpty(value)) continue; | |
if (int.TryParse(value, out var number)) | |
{ | |
Debug.WriteLine($"Number: {number,-3:D2}"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestContainer | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Email { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListDictionary | |
{ | |
private Dictionary<string, List<string>> _internalDictionary = new(); | |
public Dictionary<string, List<string>> Dictionary => _internalDictionary; | |
public bool HasItems => _internalDictionary.Count > 0; | |
public void Add(string key, string value) | |
{ | |
if (_internalDictionary.TryGetValue(key, out var item)) | |
{ |
NewerOlder