This file contains hidden or 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[] allItems = { "item1", "item2", "item3" }; | |
string[] databaseItems = { "item2" }; | |
var data = allItems | |
.SelectMany(item => databaseItems , (item, dbItem) => new { item, dbItem }) | |
.Where(x => !x.item.Equals(x.dbItem, StringComparison.InvariantCultureIgnoreCase)) | |
.Select(x => x.item); | |
foreach (var v in data) | |
Console.WriteLine(v.ToString()); |
This file contains hidden or 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
/// Input is a string with numbers : 10+20+30+40 | |
/// Output is integer with required sum (100) | |
string input = "10+20+30+40"; | |
var result = Regex.Split(input, @"\D+").Select(t => int.Parse(t)).Sum(); | |
Console.WriteLine("Result is {0}" ,result); |
This file contains hidden or 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 temp = String.Join(", ", myStringList) |
This file contains hidden or 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
Console.WriteLine(Console.ReadLine().Split(' ').Select(t => int.Parse(t)).ToList().Max()); |
This file contains hidden or 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
return categories.SelectMany(i => this.GetAllChildCategoriesIds(i.Id)); |
This file contains hidden or 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 str = "45,43,122,75,34"; | |
int[] values = str.Split(',').Select(o => Convert.ToInt32(o)).ToArray(); |
This file contains hidden or 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 list = new List<string>() { "Asia", "Africa", "North America", "South America", "Antartica", "Europe", "Australia" }; | |
var list2 = new List<string> {"Africa", "South America", "Antartica", "Foo"}; | |
// Get all items in the list that do NOT have matching items on a different list | |
var list3 = list.Except(list2).ToList(); | |
// Get all items in the list that have matching items on a different list | |
list3 = list.Intersect(list2).ToList(); |
This file contains hidden or 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 str = "H1e2l3l4l5o6"; | |
// Count all digits in a string | |
var numOfDigits = str.Count(char.IsDigit); | |
// Count all lowercase characters in a string | |
var numOfLowerCase = str.Count(char.IsLower); | |
// Count all uppercase characters within a string | |
var numOfUpperCase = str.Count(char.IsUpper); |
This file contains hidden or 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
list.ForEach(Console.WriteLine); |
This file contains hidden or 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 listWithoutDuplicates = list.Distinct().ToList(); |