C#
- .NET을 위해 개발된 언어
- C/C++, JAVA에 기반한 언어
- Event-driven language, fully OO language, visual programming language
- Event-driven은 이벤트를 발생시켜서 뭔가를 하는 언어라는 뜻이다.
- IDE를 통한 RAD(Rapid Application Development)
- IDE는 통합 개발 환경 이라는 뜻이다.(Intergrity Development Envriroment)
C#의 특징
- Language interoperability(정보 처리 상호 운용)
다른 언어로 짜여진 소프트웨어 컴포넌트들과 호환이 됨
- SOAP와 XML을 사용하여 인터넷을 통해 상호작용이 가능(이것은 APO.NET, ADO.NET의 특징이기도 함)
- 헤더파일이 없다
- 네임스페이스(자바의 패키지)와 클래스로 이루어짐
- Garbage Collector (메모리 관리자, CLR 내부에서 실행된다.)
- 다른 언어의 장점들을 끌고 왔다.
보통의 구문
using System;
class Program
{
public static void Main(string[] args)
{
string strTemp = "HELLO WORLD";
}
}
System 이라는 네임스페이스(클래스들을 그룹핑한 단위)를 이용하고
(ex printf와 같은 기능을 하는 Console.WriteLine은 System 네임스페이스를 using 해야 함..)
main 메서드를 Main()으로 하고 (메인 메서드는 M이 반드시 대문자)
static이 반드시 필요하다.
Run-time error가 나타나는 예
0으로 나누기
음수의 제곱근 구하기
숫자가 아닌 데이터로 계산
Logic error
개발자가 의도한 결과가 아닌 경우
string은 데이터의 타입인데
데이터 타입에는 여러가지가 있다.
보통 변수를 선언할때
[modifiers] datatype identifier;
로 하는데 []라는 말은 생략할 수 있다는 뜻이고, modifiers는 지정자라는 뜻이다.
지정자는 private와 public 등이 있다. 뭐가 또있는지 모르겠다..ㅠㅠ 기억이...
short 앞에 붙은 u는 unsigned로 음수는 없다는 얘기다
기본 예제들
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 삼항연산자
{
class OperatorTest
{
static void Main(string[] args)
{
int nFirst = 10;
int nSecond = 20;
int nMax = 0;
nMax = nFirst > nSecond ? nFirst : nSecond;
Console.WriteLine("nFirst는 {0}이고 nSecond는 {1}이다.", nFirst, nSecond);
Console.WriteLine("둘중 큰 수는 {0}이다.", nMax);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 자료형예제2
{
class StringTest
{
static void Main(string[] args)
{
string strText1 = " Hello "
string strText2 = " ASP.NET "
string strText3 = " World "
string strAllText = strText1 + strText2 + strText3;
Console.WriteLine("총 문자열의 길이 : {0}", strAllText.Length);
Console.WriteLine("전체 문자열 : {0}", strAllText);
Console.WriteLine("공백 제거 : {0}", strAllText.Trim());
Console.WriteLine("ASP라는 글자 삭제 : {0}", strAllText.Remove(8,3));
Console.WriteLine(".NET을 한글로 교체 : {0}", strAllText.Replace(".NET", "닷넷"));
Console.WriteLine(".NET이라는 문자열 추출 : {0}", strAllText.Substring(11,4));
Console.WriteLine("대문자로 변환 : {0}", strAllText.ToUpper());
Console.WriteLine("소문자로 변환 : {0}", strAllText.ToLower());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 표준입출력예제
{
class StdInOutTest
{
static void Main(string[] args)
{
string strName;
Console.Write("당신의 이름은 ? ");
strName = Console.ReadLine();
Console.WriteLine("Hello, {0} !", strName);
}
}
}
대충 결과가 어떻게 나올지는 알 수 있을 것
'공부' 카테고리의 다른 글
소프트웨어 실습3 - 1 (0) | 2015.03.12 |
---|---|
2주차 DB - 2 (0) | 2015.03.12 |
2주차 DB (0) | 2015.03.10 |