syneffort 2 years ago
parent b3d721afbb
commit 8a3eb1fe6f
  1. 10
      PacticeSolution/LinqInNotIn/LinqInNotIn.csproj
  2. 20
      PacticeSolution/LinqInNotIn/Product.cs
  3. 42
      PacticeSolution/LinqInNotIn/Program.cs
  4. 6
      PacticeSolution/PacticeSolution.sln

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LinqInNotIn
{
internal class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public Product(int id, string name)
{
this.ProductId = id;
this.Name = name;
}
}
}

@ -0,0 +1,42 @@
namespace LinqInNotIn
{
internal class Program
{
static void Main(string[] args)
{
List<Product> products = new List<Product>();
products.Add(new Product(1, "Scissors"));
products.Add(new Product(2, "Pencil"));
products.Add(new Product(3, "Ballpen"));
//products.Add(new Product(3, "Null Ballpen"));
products.Add(new Product(4, "Snack"));
products.Add(new Product(5, "Beverage"));
int[] ids = { 2, 4, 5 };
var inQuery = from item in products
where ids.Contains(item.ProductId)
select item;
var notInQuery = from item in products
where !ids.Contains(item.ProductId)
select item;
Console.WriteLine("inQuery");
foreach (var item in inQuery)
{
Console.WriteLine($"idx: {item.ProductId}, name: {item.Name}");
}
Console.WriteLine("notInQuery");
foreach (var item in notInQuery)
{
Console.WriteLine($"idx: {item.ProductId}, name: {item.Name}");
}
var firstItem = products.First(item => item.ProductId == 3);
var singleItem = products.Single(item => item.ProductId == 3);
Console.WriteLine($"first == single: {firstItem == singleItem}");
}
}
}

@ -121,6 +121,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTemplateSample", "DataT
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandSample", "CommandSample\CommandSample.csproj", "{AFB4006F-917A-4358-898F-8C4DC0A1E6C8}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandSample", "CommandSample\CommandSample.csproj", "{AFB4006F-917A-4358-898F-8C4DC0A1E6C8}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqInNotIn", "LinqInNotIn\LinqInNotIn.csproj", "{9261D8E1-5DEE-4329-AB32-946AD5E69C66}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -363,6 +365,10 @@ Global
{AFB4006F-917A-4358-898F-8C4DC0A1E6C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {AFB4006F-917A-4358-898F-8C4DC0A1E6C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFB4006F-917A-4358-898F-8C4DC0A1E6C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {AFB4006F-917A-4358-898F-8C4DC0A1E6C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFB4006F-917A-4358-898F-8C4DC0A1E6C8}.Release|Any CPU.Build.0 = Release|Any CPU {AFB4006F-917A-4358-898F-8C4DC0A1E6C8}.Release|Any CPU.Build.0 = Release|Any CPU
{9261D8E1-5DEE-4329-AB32-946AD5E69C66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9261D8E1-5DEE-4329-AB32-946AD5E69C66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9261D8E1-5DEE-4329-AB32-946AD5E69C66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9261D8E1-5DEE-4329-AB32-946AD5E69C66}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save