관리 메뉴

bread, coffee and coding

C# D+2 본문

C#

C# D+2

DongJin lee 2021. 7. 5. 21:33

 

 

 

밑변 5 높이 2 삼각형 넓이 구하기

 

using System;

 

namespace Quiz_Area

{

class Program

{

static void Main(string[] args)

{

int width, height;

double area;

 

Console.Write("밑변를 입력하세요");

width = int.Parse(Console.ReadLine());

 

Console.Write("높이를 입력하세요");

 

height = int.Parse(Console.ReadLine());

 

area = (double)height * width / 2;

 

 

Console.Write("Area: ");

Console.WriteLine(area);

}

}

}

 

---------------------------------------------------------------------------------

 

 

p42 , 43, 44

 

using System;

 

namespace ConsoleApp4

{

class Program

{

static void Main(string[] args)

{

int a = 100;

 

{

a = 200;

int b = 400;

}

 

Console.WriteLine(a);

// Console.WriteLine(b); //변수가 존재하지 않는다

 

}

}

}

------------------------------------------------------------------

 

p48

 

using System;

 

namespace FloatingPoint

{

class Program

{

static void Main(string[] args) //60p

{

float a = 3.1415_9265_3589_7932_3846f;

Console.WriteLine(a);

 

double b = 3.1415_9265_3589_7932_3846;

Console.WriteLine(b);

 

decimal c = 3.1415_9265_3589_7932_3846m; //decimal 에 별표 하나 치기

Console.WriteLine(c); //다른 언어에 없는 새로운 타입 128bit

 

}

}

}

 

-------------------------------------------------------------------------------

 

##2021-05-06##

using System;

 

namespace Test_Enum

{

//참조 0

class Program

{

//참조6

enum DialogResult { YES, NO, CANCEL, CONFIRM=70, OK } //Type(자료형), 열거형

//참조 0

static void Main(string[] args)

{

DialogResult result = DialogResult.YES;

 

 

Console.WriteLine((int)(DialogResult.YES)); //()형변환 연산자 : casting

Console.WriteLine((int)(DialogResult.NO));

Console.WriteLine((int)(DialogResult.CANCEL));

Console.WriteLine(result == DialogResult.CANCEL);

Console.WriteLine((int)(DialogResult.CONFIRM));

Console.WriteLine((int)(DialogResult.OK));

 

}

}

}

 

 

 

nullable 형식

using System;

 

namespace Test_Enum

{

 

class Program

{

static void Main(string[] args)

{

int? a = null; // nullable 형식

 

 

Console.WriteLine(a.HasValue);

Console.WriteLine(a != null); // -> false

 

a = 3; //3이라는 이벤트를 받았다 .

 

Console.WriteLine(a.HasValue);

Console.WriteLine(a != null);

Console.WriteLine(a.Value);

}

}

}

 

 

 

##Nullable 형식

int a = null; -> 오류

int? a = null;

ex)

int? a = null;

 

Console.WriteLine(a.HasValue);

Console.WriteLine(a != null);

 

-> false , false

 

-------------------------------------------

 

p92 중요

using System;

 

namespace Test_Enum

{

 

class Program

{

static void Main(string[] args)

{

System.Int32 a = 123;

int b = 123;

 

a = b;

b = a;

 

Console.WriteLine(a.GetType());

Console.WriteLine(b.GetType());

 

}

}

}

 

 

--------------------------------------------------------------------------

 

 

p94 문자열 찾기 매우 중요

 

using System;

 

namespace MyPP_04_StringConcatenate

{

class Program

{

static void Main(string[] args)

{

int result = 123 + 456;

string result2 = "123" + "456";

//string result2 = "123" + 456; -> 확인해보기

string result3 = "안녕" + "하세요";

Console.WriteLine(result);

Console.WriteLine(result2);

Console.WriteLine(result3);

}

}

}

 

----------------------------------------------

using System;

 

namespace IncDecOperator

{

class Program

{

static void Main(string[] args)

{

int a = 0;

// a = a +1;

// a++;

//Console.WriteLine(++a); //먼저 1을 올려주고 증가

//Console.WriteLine(++a) --> 결과값 확인해서 이해하기

//Console.WriteLine("{0},{1}", ++a, a++); ->> 이런 코드는 쓰지말라

//Console.WriteLine("{0},{1}, {2}", ++a, a++, a++); ->> 이런 코드는 쓰지말라 한라인에 증감연산자 사용 x

Console.WriteLine($"{a++}"); //1

Console.WriteLine($"{a--}"); //1

Console.WriteLine(a); //0

}

}

}

 

 

using System;

 

namespace MyApp_04_Realtional

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine($" 3 > 4 : {3 > 4} "); //관계연산자

Console.WriteLine($" 3 != 4 : {3 != 4} ");

 

Console.WriteLine(1 > 0 && 4 < 5);

/*진리표

AND 연산자

0 0 0

0 1 0

1 0 0

1 1 1

OR 연산자

0 0 0

0 1 1

1 0 1

1 1 1 */

 

// &&, ||, ! (AND, OR, NOT) -> 논리 연산자

 

 

}

}

}

 

 

using System;

 

namespace MyApp_04_Realtional

{

class Program

{

static void Main(string[] args)

{

 

int result;

 

result = 10 - (2 * 5);

 

Console.WriteLine(result);

 

}

}

}

 

 

/-/-/-/-/-/-/-/-/-/-/-/-/////////////////////////////////////////////////////////

 

 

 

using System;

 

namespace MyApp_04_Realtional

{

class Program

{

static void Main(string[] args)

{

int i = 1;

 

while( i <= 10 )

{

Console.WriteLine(i++); //f9 누르고 빌드에 디버깅 시작 눌르기 //f11눌러서 한단계 진행 되는것 까지 확인

}

 

}

}

}

 

 

 

using System;

 

namespace MyApp_04_Realtional

{

class Program

{

static void Main(string[] args)

{

int i = 1;

 

while (i<=100)

{

if (i % 2 != 1)

{

Console.Write(i++ +" ");

}

else

i++; // 중요 안적어주면 무한루프가 된다

}

return;

 

 

}

}

}

----------------------------------------------------------------

using System;

 

namespace MyApp_04_Realtional

{

class Program

{

static void Main(string[] args)

{

for (int i = 0; i <= 10; i++)

{

Console.WriteLine(i);

}

 

 

}

}

}

 

 

using System;

 

namespace MyApp_04_Realtional

{

class Program

{

static void Main(string[] args)

{

for (int i = 0; i <= 10; i++)

{

Console.WriteLine(i);

}

 

 

}

}

}

 

 

using System;

 

 

 

namespace MyApp_04_Realtional

 

{

 

class Program

 

{

 

static void Main(string[] args)

 

{

 

int sum = 0;

 

for (int i = 1; i <= 100; i++)

 

{

 

sum = sum + i;

 

}

 

Console.WriteLine(sum);

 

}

 

}

 

 

using System;

 

 

 

namespace MyApp_04_Realtional

 

{

 

class Program

 

{

 

static void Main(string[] args)

 

{

int i = 1;

int sum = 0;

 

while (i < 101)

 

{

sum = sum + i;

i++;

}

 

Console.WriteLine(sum);

 

}

 

}

 

}

 

 

 

'C#' 카테고리의 다른 글

C# D+5  (0) 2021.07.05
C# D+4  (0) 2021.07.05
C# D+3  (0) 2021.07.05
C# D+1  (0) 2021.05.05