[C#]ThisπŸ”Ž

κΉ€κ·Όλ©΄Β·2022λ…„ 6μ›” 17일
0

μ•Œμ•„λ³΄μž C#

λͺ©λ‘ 보기
3/3
post-thumbnail

μ•Œμ•„λ³΄μž λ””μŠ€(this)

πŸ‘‰ thisλž€ 일반적으둜 객체가 자기 μžμ‹ μ„ 지칭할 λ•Œ μ‚¬μš©ν•˜λŠ” ν‚€μ›Œλ“œμ΄λ‹€. 객체 μ™ΈλΆ€μ—μ„œλŠ” 객체의 λ³€μˆ˜λ‚˜ λ©”μ†Œλ“œμ— μ ‘κ·Όν•˜κΈ° μœ„ν•΄μ„œ 객체의 이름을 μ‚¬μš©ν•˜μ§€λ§Œ 객체 λ‚΄λΆ€μ—μ„œλŠ” μžμ‹ μ˜ λ³€μˆ˜λ‚˜ λ©”μ†Œλ“œμ— μ ‘κ·Ό ν•  λ•Œ, thisν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ ν‘œν˜„ν•œλ‹€.

πŸ‘¨πŸ»β€πŸ’»μ˜ˆμ œ

using System;

namespace this
{
	class NASDAQ
    {
    	private string transactionprice;
        private string estimatedprice;

        public void SetTransactionprice(string transactionprice)
        {
            this.transactionprice = transactionprice;
        }

        public string GetTransactionprice()
        {
            return transactionprice;
        }

        public void SetEstimatedprice(string estimatedprice)
        {
            this.estimatedprice = estimatedprice;
        }

        public string GetEstimatedprice()
        {
            return this.estimatedprice; 
        }
    }
    class Program
    {
        static void Main(string[] args)
        {           
            NASDAQ AAPL = new NASDAQ();
            AAPL.SetTransactionprice("μ• ν”Œ κ±°λž˜κ°€ - 130.06 USD");
            AAPL.SetEstimatedprice("μ• ν”Œ μ˜ˆμƒκ°€ - 133.16 USD");
            Console.WriteLine("{0} {1}", AAPL.GetTransactionprice(), AAPL.GetEstimatedprice());

            NASDAQ AMZN = new NASDAQ();
            AMZN.SetTransactionprice("μ•„λ§ˆμ‘΄ μ‹€κ±°λž˜κ°€ - 103.66 USD");
            AMZN.SetEstimatedprice("μ•„λ§ˆμ‘΄ μ˜ˆμƒκ°€ - 104.11 USD");
            Console.WriteLine("{0} {1}", AMZN.GetTransactionprice(), AMZN.GetEstimatedprice());
        }

    }
}

πŸ‘‰ 예제의 경우 처럼 μΈμŠ€ν„΄μŠ€ λ³€μˆ˜ transactionprice와 SetTransactionpriceλ©”μ†Œλ“œμ˜ λ§€κ°œλ³€μˆ˜ transactionprice의 λͺ…칭이 λ™μΌν•˜μ—¬ ꡬ뢄이 μ•ˆ 될 κ²½μš°μ— μΈμŠ€ν„΄μŠ€ λ³€μˆ˜μ— thisν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ this.transactionprice은 μΈμŠ€ν„΄μŠ€ λ³€μˆ˜, transactionprice은 λ§€κ°œλ³€μˆ˜μ—μ„œ μ •μ˜λœ 지역 λ³€μˆ˜λ‘œ ꡬ뢄을 ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ˜€λŠ˜μ€ 이제 그만 μ•Œμ•„λ³΄μžπŸ€—

profile
cheer about the man right next to you

0개의 λŒ“κΈ€