반응형
네임스페이스? using?
C#의 네임스페이스란 자바의 패키지와 같다.
C#의 using은 자바의 import와 같다.
고 생각하면 된다.
using 사용법
using System;
namespace Application1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
}
}
}
using을 사용하지 않는다면
namespace Application1
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello, world!");
}
}
}
이런 식으로 사용하면 된다.
네임스페이스 사용법
아래와 같이 Application1, Application2가 있다.
그리고 각각의 어플리케이션은 consoleWrite라는 같은 이름의 함수를 가지고 있다. 어떻게 접근하면 좋을까?
using System;
namespace Application1
{
class Class1
{
static void consoleWrite()
{
Console.WriteLine("I'm Application1.");
}
}
}
using System;
namespace Application2
{
class Class2
{
static void consoleWrite()
{
Console.WriteLine("I'm Application2.");
}
}
}
이렇게 사용하면 된다.
using System;
{
class Program
{
static void Main(string[] args)
{
Application1.Class1.ConsoleWrite(); // I'm Application1. 출력됨
Application2.Class2.ConsoleWrite(); // I'm Application2. 출력됨
}
}
}
솔루션? 프로젝트?
솔루션은 여러 프로젝트의 묶음이다.
확장자는 sln이다.
프로젝트의 build 폴더 관리
Ctrl+Shift+B를 누르면 프로젝트를 빌드할 수 있다.
빌드 후 만들어진 exe 파일은 기본적으로 해당 프로젝트 폴더의 bin/Debug 폴더에 들어 있다.
cmd에서 해당 폴더의 위치로 가서 exe파일을 실행해볼 수 있다.
build 폴더 위치 변경
build 폴더는
프로젝트 우클릭-속성-빌드-출력에서 변경할 수 있다.
App.config 파일은 뭔데?
프로젝트의 설정을 담는 파일이다.
Java의 XML파일과 유사하다고 이해했다.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<appSettings>
<add key="key" value="value"/>
</appSettings>
<connectionStrings>
<add name="TestString" connectionString="ABCDE"/>
</connectionStrings>
</configuration>
using System;
{
class Program
{
static void Main(string[] args)
{
string str = ConfigurationManager.AppSettings["key"];
Console.WriteLine(str); // value 출력
string testStr = ConfigurationManager.ConnectionStrings["TestString"].ConnectionString;
Console.WriteLine(testStr); // ABCDE 출력
}
}
}
https://joseph-han.tistory.com/33
[C#][기초] App.config 활용하기
설정 정보 활용 프로그램을 구현해서 사용하다가 보면 프로그램을 수정하지 않고 동적으로 입력 값을 변환하여 사용하고 싶을 때가 있다. 그럴 때 프로그램의 시작 인자(parameter)를 활용한다. 하
joseph-han.tistory.com
반응형
'C# > 이것이 C#이다' 카테고리의 다른 글
6장. 확장메소드, this와 ref, out, params 등 키워드, string.Empty (0) | 2023.04.19 |
---|---|
5장. 값 형식과 참조 형식, 박싱과 언박싱 (0) | 2023.04.18 |
4장. 데이터의 흐름 제어: 분기문, 반복문 (0) | 2023.04.18 |
3장. 데이터 보관하기: 자료형, 배열, 형 변환, 형식 확인, 입출력 (0) | 2023.04.18 |
1장. C# 자바 비교 및 차이점, Visual Studio 환경설정 (0) | 2023.04.18 |