c# 기초구문 업데이트 완료

This commit is contained in:
2025-03-05 11:57:12 +09:00
parent 15885a2286
commit 6ebd0fb5a9
22 changed files with 740 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+45
View File
@@ -0,0 +1,45 @@
internal class Program
{
private static void Main(string[] args)
{
var db = new DataBase { DBName = "mydb"};
// 쿼리식 표현
var v = from ord in db.Orders
where ord.Customer_ID == "FRANS"
orderby ord.Order_Date ascending
select ord;
// 메서드식 표현1
var w = db.Orders.Where(order => order.Customer_ID == "FRANS").Select(o => o);
// 메서드식 표현2
// 위의 메서드식 표현1의 Select()메서드는 동일데이타를
// 변형없이 리턴하므로 생략가능
var x = db.Orders.Where(order => order.Customer_ID == "FRANS");
x.Select((item, index) => new { IDX = index, ITEM = item });
//기타 확장메서드
x.First();
x.FirstOrDefault();
x.Last();
var l = x.ToList();
l.ForEach(item => Console.WriteLine(item.Customer_ID));
x.Select(item => item.Order_Date).Distinct();
}
}
class DataBase
{
public string DBName = string.Empty;
public List<Order> Orders = new();
}
class Order
{
public string Customer_ID = string.Empty;
public DateTime Order_Date;
public List<string> Items = new();
}