Here is an Linq extension which returns your custom error message in cause of an exception. Linq Implemented: First, Last, Single, MinOrDefault, MaxOrDefault, AverageOrDefault String Implemented: Left, Right Stopwatch: ToFormatedString
For funny reason you can use Highlander instead of Single :)
- .NET 8.0
- .NET 6.0
- .NET Standard 2.0
- .NET 4.8
List<string> newList = new List<string> {"1234", "987654"};
newList.SingleOrDefault(x => x == "searchString", "custom error message e.g. search string mot in list");
List<int> newList = new List<int> {1234, 987654};
newList.Select(x => x).MinOrDefault();
var dataList = new List<decimal>() { 15.2M, 18.6M, 55.23M };
var result = dataList.Select(x => x).MaxOrDefault();
var dataList = new List<decimal>() { 15.2M, 18.6M, 55.23M };
var result = dataList.Select(x => x).AverageOrDefault();
string testString = "anyTestText";
var result = testString.Left(4);
// result == "anyT"
string testString = "anyTestText";
var result = testString.Right(4);
// result == "Text"
string testString = "Add Additional String";
var result = testString.ReplaceExactWord("Add", "Insert");
// result == "Insert Additional String"
var result = m_Stopwatch.ToFormatedString("g")
// result == "0:00:01,5"
var result = m_Stopwatch.ToFormatedString(@"mm\:ss\.ff")
// result == "00:01.50"
DateTime result = new DateTime(2019, 1, 22).WeekBeginn();
// result == new DateTime(2018, 12, 31)
int result = new DateTime(2016, 2, 22).DaysInMonth()
// result == 29