오라클자바커뮤니티에서 설립한 오엔제이프로그래밍
실무교육센터
(오라클SQL, 튜닝, 힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷 실무전문 강의)
------------------------------
User-Defined Data Types
--------------------------
1. Enumeration Type
정의 : enum Color { Red , Green , Blue }
사용법 : Color colorPalette = Color.Red; , Console.WriteLine(“{0}” , colorPalette); //display Red
[예제]
using System;
namespace ConsoleApplication
{
enum Day
{
Monday, Thesday, Wednesday, Thursday, Friday, Saturday, Sunday
}
public class EnumTest
{
static void Main()
{
Day whatDay = Day.Monday;
Console.WriteLine("{0}", whatDay);
whatDay = (Day)1;
Console.WriteLine("{0}", whatDay);
}
}
}
[결과]
Monday
Thesday
2. Structure Types
여러가지 형식의 자료들을 모아둔 틀이며 C#에서는 메소드가 없는 클래스 입니다.
구조체의 정의 방법
public struct Employee
{
String firstname;
Int age;
}
사용 방법
Employee companyEmployee;
companyEmployee.firstname = “ Joe ” ;
companyEmployee.age = 23;
[예제]
using System;
struct Emp
{
public int id;
public string name;
}
class EmpTest
{
public static void Main()
{
Emp e;
e.id = 1;
e.name = "1길동";
Console.WriteLine("사번: {0}",e.id);
Console.WriteLine("이름: {0}",e.name);
}
}
[결과]
Monday
Thesday
댓글 없음:
댓글 쓰기