개발 노트

변수,상수 본문

프로그래밍/C#

변수,상수

알 수 없는 사용자 2022. 1. 11. 11:24

변수

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int i = 12345;
            char c = 'A';
            float f = 3.14f;
            double d = 42.195;
            string s = "문자열";
            int maxInt = int.MaxValue;

            Console.WriteLine("{0:c}, {1:d}, {2:c}, {3:e}", i, i, i, i);
            Console.WriteLine("{0}", c);
            Console.WriteLine("{0:f}, {1:0.0}, {2:0.000}", f, f, f);
            Console.WriteLine("{0:f}, {1:g}, {2:n}", d, d, d);
            Console.WriteLine("{0:g}, {1:g}, {2:g}", c, s, maxInt);


        }
    }
}

컨트롤 f5를 누르면 결과 값이 나온다

 

포멧형식은 통화(Currency){0:c} 이런형식으로 12345를 넣었을때 \12,345 로 나옴

{2:c} 의 의미는 3번째 있는 변수 i(12345)를  Currency(화폐) 형식

 

상수

using System;

namespace ConsoleApp1
{

    class Program
    {

        static void Main(string[] args)
        {
            const double PI = 3.14;

            double R = 3;
            double circumference = 2 * PI * R;
            double area = R * R * PI;

            Console.WriteLine("원의 둘레 = {0}", circumference);
            Console.WriteLine("원의 넓이 = {0}", area);


        }
    }
}

상수는 값을 변경하면 오류가 난다

'프로그래밍 > C#' 카테고리의 다른 글

간단한 사칙연산 프로그램  (0) 2022.01.11
c# 조건문,switchcase  (0) 2022.01.11
비주얼스튜디오 c#프로젝트를 선택할때  (0) 2022.01.11
c#스터디 패널,객체  (0) 2022.01.11
ftp-파일질라서버참고사이트  (0) 2022.01.10