일반
변수,상수
알 수 없는 사용자
2022. 1. 11. 11:24
SMALL
변수
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);
}
}
}
상수는 값을 변경하면 오류가 난다
LIST