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
| using Microsoft.EntityFrameworkCore; | |
| using Microsoft.AspNetCore.Diagnostics; | |
| var builder = WebApplication.CreateBuilder(args); | |
| builder.Services.AddEndpointsApiExplorer(); | |
| builder.Services.AddSwaggerGen(); | |
| builder.Services.AddDbContext<ApiContext>(opt => opt.UseInMemoryDatabase("SampleDB")); | |
| var app = builder.Build(); | |
| app.Use(async (context, next) => |
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
| public class ZipExample | |
| { | |
| public IEnumerable<(string, string)> Sample1() | |
| { | |
| var colors1 = new List<string>() { "Red", "Green", "Blue", "Black" }; | |
| var colors2 = new List<string>() { "Purple", "White", "Blue", "Red" }; | |
| var result = colors1.Zip(colors2); | |
| // result = IEnumerable<(string,string)>() { ("Red", "Purple"), ("Green", "White"), ("Blue", "Blue"), ("Black", "Red") } | |
| return 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
| public class WhereExample | |
| { | |
| public IEnumerable<string> Sample1() | |
| { | |
| var colors = new List<string>() { "Red", "Green", "Blue", "Black" }; | |
| var result = colors.Where(x => x.Length > 4); | |
| // result = IEnumerable<string> { "Green", "Black" } | |
| return 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
| public class UnionExample | |
| { | |
| public IEnumerable<string> Sample1() | |
| { | |
| var colors1 = new List<string>() { "Red", "Green", "Blue", "Black" }; | |
| var colors2 = new List<string>() { "Purple", "White", "blue", "Red" }; | |
| var result = colors1.Union(colors2); | |
| // result = IEnumerable<string>() { "Red", "Green", "Blue", "Black", "Purple", "White", "blue" } | |
| return 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
| public class UnionByExample | |
| { | |
| public IEnumerable<string> Sample1() | |
| { | |
| var colors1 = new List<string>() { "Red", "Green", "Blue", "Black" }; | |
| var colors2 = new List<string>() { "Purple", "White", "blue", "Red" }; | |
| var result = colors1.UnionBy(colors2, x => x.Substring(0, 2)); | |
| // result = IEnumerable<string>() { "Red", "Green", "Blue", "Purple", "White", "blue" } | |
| return 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
| public class TryGetNonEnumeratedCountExample | |
| { | |
| public (bool, int) Sample1() | |
| { | |
| var colors = new List<string>() { "Red", "Green", "Blue", "Black" }; | |
| var result = colors.TryGetNonEnumeratedCount(out int count); | |
| // result = true (no iteration needed to find count) | |
| // count = 4 (no iteration needed so returned count) | |
| return (result, count); | |
| } |
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
| public class ToLookupExample | |
| { | |
| public ILookup<bool, string> Sample1() | |
| { | |
| var colors = new List<string>() { "Red", "Green", "Blue", "Black" }; | |
| var result = colors.ToLookup(x => x.Length > 4); | |
| // result = ILookup<bool, string> [ { Key: false, Items: [ "Red", "Blue" ] }, { Key: true, Items: [ "Green", "Black" ] } ] | |
| return 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
| public class ToListExample | |
| { | |
| public IEnumerable<string> Sample1() | |
| { | |
| IEnumerable<string> colors = new List<string>() { "Red", "Green", "Blue", "Black" }; | |
| var result = colors.ToList(); | |
| // result = List<string> { "Red", "Green", "Blue", "Black" } | |
| return 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
| public class ToHashSetExample | |
| { | |
| public HashSet<string> Sample1() | |
| { | |
| var colors = new List<string>() { "Red", "Green", "Blue", "Black", "red" }; | |
| var result = colors.ToHashSet(); | |
| // result = HashSet<string> { "Red", "Green", "Blue", "Black", "red" } | |
| return 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
| public class ToDictionaryExample | |
| { | |
| public Dictionary<string, string> Sample1() | |
| { | |
| var colors = new List<string>() { "Red", "Green", "Blue", "Black", "red" }; | |
| var result = colors.ToDictionary(x => x.Substring(0, 3)); | |
| // result = Dictionary<string, string> { { Key: "Red", Value: "Red" }, { Key: "Gre", Value: "Green" }, { Key: "Blu", Value: "Blue" }, { Key: "Bla", Value: "Black" }, { Key: "red", Value: "red" } } | |
| return result; | |
| } |
NewerOlder