Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- C#
- String
- W3Schools
- python
- dynamic
- 프로그래밍
- Unity
- 백준
- w3school
- 기초
- Programming
- github
- 시작해요 언리얼 2022
- c++
- Unreal Engine 5
- Basic
- loop
- guide
- Material
- UE5
- parameter
- 문제풀이
- dfs
- 재귀
- Algorithm
- 파이썬
- Class
- DP
- 오류
- Tutorial
Archives
- Today
- Total
행복한 개구리
C# 21.04.05.복습 본문
튜플
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class App
{
eGrade grade;
enum eGrade { NORMAL, MAGIC, RARE, LEGENDARY, MYTHIC }
public App()
{
Console.WriteLine("App 생성자 호출됨");
(int id, string name) item = (1, "사탕");
Console.WriteLine("{0} : {1}", item.id, item.name);
Random rand = new Random();
int index = rand.Next(0, 5);
if (index == 0) { this.grade = eGrade.NORMAL; }
else if (index == 1) { this.grade = eGrade.MAGIC; }
else if (index == 2) { this.grade = eGrade.RARE; }
else if (index == 3) { this.grade = eGrade.LEGENDARY; }
else { this.grade = eGrade.MYTHIC; }
(string name, eGrade gName) item2 = ("막대사탕", this.grade);
Console.WriteLine("{0} // {1}", item2.name, item2.gName);
}
}
}
============================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class App
{
private int[,] arr;
private int row;
private int col;
public App()
{
Console.WriteLine("App 생성자 호출됨");
this.arr = new int[4, 3];
this.row = arr.GetLength(0);
this.col = arr.GetLength(1);
this.arr[1, 2] = 100;
Console.WriteLine("1차시 [1,2] = 100--------");
this.PrintArray();
arr[2, 0] = 200;
Console.WriteLine("2차시 [2,0] = 200--------");
this.PrintArray();
Indexes indexesA = new Indexes(1, 2);
Indexes indexesB = new Indexes(2, 0);
this.Swap(indexesA, indexesB);
Console.WriteLine("3차시 스왑 [1,2], [2,0]--------");
this.PrintArray();
this.Swap(new Indexes(0, 0), new Indexes(2, 0));
Console.WriteLine("4차시 스왑[0,0], [2,0]--------");
this.PrintArray();
}
private void Swap(Indexes a, Indexes b)
{
int temp = arr[b.rowIndex, b.colIndex];
arr[b.rowIndex, b.colIndex] = arr[a.rowIndex, a.colIndex];
arr[a.rowIndex, a.colIndex] = temp;
}
private void PrintArray()
{
for (int i = 0; i < this.row; i++)
{
for(int j = 0; j < this.col; j++)
{
Console.Write("{0, 5}", arr[i, j]);
}
Console.WriteLine();
}
}
}
}
============================================================================
오늘은 일찍 자야지 ㅎㅎ
++) 하나 더 했다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class App
{
public App()
{
Console.WriteLine("App 생성자 호출됨");
List<Book> books = new List<Book>();
var book1 = new Book()
{
ID = "bk109",
Title = "어린왕자",
Genre = "Novel",
PublishDate = new DateTime(2002, 01, 01)
};
var book2 = new Book()
{
ID = "bk108",
Title = "콩쥐팥쥐",
Genre = "Novel",
PublishDate = new DateTime(2002, 01, 02)
};
Console.WriteLine(book1.ToString());
books.Add(book1);
books.Add(book2);
/* List<Book> list = books.FindAll(FindComputer);
foreach(Book book in list)
{
Console.WriteLine(book.ToString());
}*/
List<Book> list = books.FindAll((book) =>
{
if (book.Genre == "Novel") return true;
else return false;
});
Console.WriteLine(list.Count);
foreach(var book in list)
{
Console.WriteLine(book.ToString());
}
}
private bool FindComputer(Book book)
{
if (book.Genre == "Novel")
return true;
else
return false;
}
}
}
List<Book> list = books.FindAll((book) => ~~~~
부분이 잘 안 와닿았는데 하다보니까 books 에서 FIndAll로 true를 반환한 값들이 하나의 리스트가 되어 list에 할당된 것 이라고 이해됐다.(맞겠지?)
'C# > 복습' 카테고리의 다른 글
C#21.03.29.복습 (0) | 2021.03.29 |
---|---|
C#21.03.26~28.복습 (0) | 2021.03.26 |
C# 21.03.25.복습 (0) | 2021.03.25 |
C# 21.03.23.복습 (0) | 2021.03.23 |