-
03/23 List<T>.Find(Predicate<T>) 메서드 연습C#/수업내용 2021. 3. 23. 12:46
Program.cs
using System; namespace Study07 { class Program { static void Main(string[] args) { Console.WriteLine("Program"); new App(); } } }
App.cs
using System; using System.Collections.Generic; using System.Linq; namespace Study07 { public class Book { public string ID { get; set; } public string Title { get; set; } } public class App { //생성자 public App() { Console.WriteLine("App"); //컬렉션 인스턴스화 List<Book> books = new List<Book>(); //books.Find(delegate (Book book) //{ // return book.ID == "bk109"; //}); books.Add(new Book() { ID = "bk109", Title = "어린왕자" }); Book foundBook = books.Find((book) => book.ID == "bk109"); if (foundBook != null) { Console.WriteLine("{0}, {1}", foundBook.ID, foundBook.Title); } } } }
'C# > 수업내용' 카테고리의 다른 글
03/24 Event연습 (0) 2021.03.24 03/23 수업내용 메모 (0) 2021.03.23 03/23 Linq Where 연습 (0) 2021.03.23 03/23 Linq Find, Where, FindAll, Sort 연습 (0) 2021.03.23 03/22 델리게이트 연습 7 (0) 2021.03.22