C#/C#

C#(4) : 산술연산자와 함수

Rainbow🌈Coder 2022. 1. 21. 22:29
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