728x90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class User
{
private int Hp = 100;
public void Damage(int _Hp)
{
Hp -= 10;
}
public int Plus(int _Left, int _Right)
{
int Result = _Left + _Right;
return Result;
}
}
namespace Example
{
class Program
{
static void Main(string[] args)
{
User NewUser = new User();
int Result = 0;
int Left = 7;
int Right = 3;
//논리 연산자
bool BResult = true;
BResult = Left > Right;
BResult = !(Left > Right);//true면 false
//BResult = !true;
BResult = !(Right > Left);//false면 true
//BResult = !false;
BResult = true && false; //AND
BResult = true || false; //OR
//XOR이란, 다르다면 true, 같다면 false
BResult = true ^ true; //false
BResult = false ^ false; //false
BResult = true ^ false; //true
BResult = false ^ true; //true
}
}
}
함수의 경우 : 리턴값은 외부에 반환
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class User
{
private int Hp = 100;
public void Damage(int _Hp)
{
Hp -= 10;
}
public int Plus(int _Left, int _Right)
{
int Result = _Left + _Right;
return Result;
}
}
namespace Example
{
class Program
{
static void Main(string[] args)
{
User NewUser = new User();
int Result = 0;
int Left = 7;
int Right = 3;
//함수
Result = NewUser.Plus(Left, Right);
}
}
}
산술연산자의 경우
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class User
{
private int Hp = 100;
public void Damage(int _Hp)
{
Hp -= 10;
}
}
namespace Example
{
class Program
{
static void Main(string[] args)
{
User NewUser = new User();
int Result = 0;
int Left = 7;
int Right = 3;
//산술연산자
Result = Left + Right;
}
}
}
논리연산자의 활용
static void Main(string[] args)
{
User NewUser = new User();
int Result = 0;
int Left = 7;
int Right = 3;
//논리 연산자
bool BResult = true;
BResult = Left > Right;
}
728x90
'C# > C#' 카테고리의 다른 글
C# 가변배열 (0) | 2022.01.22 |
---|---|
C#(5) : 값형식의 메모리 구조 및 처리 vs 래퍼런스의 메모리 구조 및 처리 (0) | 2022.01.22 |
C#(3) : 멤버변수, 멤버함수, 지역변수, 접근제한지정자(캡슐화, 은닉화) (0) | 2022.01.21 |
C#(2) os가 C#코드를 읽는 순서, ide와 함께하는 기초 디버깅 f10 (0) | 2022.01.21 |
C#(1) 클래스(설계도) 먼저, 그 다음 객체 | namespace (0) | 2022.01.21 |