Last active
April 21, 2021 19:26
-
-
Save kshyju/75bb3db0c2832cda85f40ee72494c665 to your computer and use it in GitHub Desktop.
LinqVsMyLinq-For-JB_Reference
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 Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace WebApplication2 | |
{ | |
public class Startup | |
{ | |
// This method gets called by the runtime. Use this method to add services to the container. | |
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseRouting(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapGet("/", async context => | |
{ | |
await context.Response.WriteAsync("Hello World!"); | |
}); | |
endpoints.MapGet("/my-linq", async context => | |
{ | |
string[] requestFlightIds = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", Guid.NewGuid().ToString() }; | |
string[] configFlightIds = new string[] { "x", "di", "y", Guid.NewGuid().ToString() }; | |
var exi = MyExist(requestFlightIds, configFlightIds); | |
await context.Response.WriteAsync($"MY-LINQ {exi}"); | |
}); | |
endpoints.MapGet("/linq", async context => | |
{ | |
string[] requestFlightIds = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", Guid.NewGuid().ToString() }; | |
string[] configFlightIds = new string[] { "x", "di", "y", Guid.NewGuid().ToString() }; | |
var exi = requestFlightIds.Intersect(configFlightIds).Any(); | |
await context.Response.WriteAsync($"LINQ {exi}"); | |
}); | |
}); | |
} | |
bool MyExist(string[] flightIds, string[] configFlightIds) | |
{ | |
for (var i = 0; i < flightIds.Length; i++) | |
{ | |
for (var j = 0; j < configFlightIds.Length; j++) | |
{ | |
if (flightIds[i] == configFlightIds[j]) | |
{ | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment