서울 성공회대학교 소프트웨어공학과 학생들을 가르치면서 과제로 내 준 내용을 정리해 보았으며 세부내용은 다음과 같습니다.
- myInformation.dll 파일
namespace myInformation
{
public class Book
{
public string title; //도서명
public string author; // 저자
public string publisher; // 출판사
public Book(string intitle, string inauthor, string inpublisher)
{
title = intitle;
author = inauthor;
publisher = inpublisher;
}
}
public class Music
{
public string title; //노래명
public string singer; //가수
public int rank; //순위
public Music(string intitle, string insinger, int inrank) //생성자
{
title = intitle;
singer = insinger;
rank = inrank;
}
}
public class Person
{
public string name; //이름
public string relation; //관계 예 : 친구,가족,동료
public string cellPhone; //휴대폰 번호
public Person(string inname, string inrelation, string incellPhone) //생성자
{
name = inname;
relation = inrelation;
cellPhone = incellPhone;
}
}
- myInformationView 파일
...
using myInformation;
namspace myInformationView
class Program
{
delegate void ShowBook(Book inBook);
delegate void ShowMusic(Music inMusic);
delegate void ShowPerson(Person inPerson);
static void Main(string[] args)
{
Book myBook = new Book("부의 미래", "앨빈 토플러", "청림");
Music myMusic = new Music("꿈에", "박정현", 3);
Person myPerson = new Person("백장현", "스승", "010-3334-5555");
ShowBook sBook = myBook_Display;
ShowMusic sMusic = myMusic_Display;
ShowPerson sPerson = myPerson_Display;
sBook(myBook);
sMusic(myMusic);
sPerson(myPerson);
Console.ReadLine();
}
static void myBook_Display(Book inBook)
{
Console.Write("책이름 : " + inBook.title + "\t");
Console.Write("저자 : " + inBook.author + "\t");
Console.Write("출판사 : " + inBook.publisher +"\n");
}
static void myMusic_Display(Music inMusic)
{
Console.Write("곡명 : " + inMusic.title + "\t");
Console.Write("가수 : " + inMusic.singer+ "\t");
Console.Write("순위 : " + inMusic.rank + "\n");
}
static void myPerson_Display(Person inPerson)
{
Console.Write("이름 : " + inPerson.name + "\t");
Console.Write("관계 : " + inPerson.relation + "\t");
Console.Write("휴대폰번호 : " + inPerson.cellPhone + "\n");
}
}
위와 같이 myInformation dll 파일을 참조하게 한 후 대리자에 클래스 형태로 입력 파라미터를 넘겨서 원하는 작업을 수행할 수 있습니다.
친애하는 학생여러분! 열심히 복습하고 이 코드를 응용해보기 바라며 실력을 쌓아서 좋은 곳에 취업되길 바란다.
- myInformation.dll 파일
namespace myInformation
{
public class Book
{
public string title; //도서명
public string author; // 저자
public string publisher; // 출판사
public Book(string intitle, string inauthor, string inpublisher)
{
title = intitle;
author = inauthor;
publisher = inpublisher;
}
}
public class Music
{
public string title; //노래명
public string singer; //가수
public int rank; //순위
public Music(string intitle, string insinger, int inrank) //생성자
{
title = intitle;
singer = insinger;
rank = inrank;
}
}
public class Person
{
public string name; //이름
public string relation; //관계 예 : 친구,가족,동료
public string cellPhone; //휴대폰 번호
public Person(string inname, string inrelation, string incellPhone) //생성자
{
name = inname;
relation = inrelation;
cellPhone = incellPhone;
}
}
- myInformationView 파일
...
using myInformation;
namspace myInformationView
class Program
{
delegate void ShowBook(Book inBook);
delegate void ShowMusic(Music inMusic);
delegate void ShowPerson(Person inPerson);
static void Main(string[] args)
{
Book myBook = new Book("부의 미래", "앨빈 토플러", "청림");
Music myMusic = new Music("꿈에", "박정현", 3);
Person myPerson = new Person("백장현", "스승", "010-3334-5555");
ShowBook sBook = myBook_Display;
ShowMusic sMusic = myMusic_Display;
ShowPerson sPerson = myPerson_Display;
sBook(myBook);
sMusic(myMusic);
sPerson(myPerson);
Console.ReadLine();
}
static void myBook_Display(Book inBook)
{
Console.Write("책이름 : " + inBook.title + "\t");
Console.Write("저자 : " + inBook.author + "\t");
Console.Write("출판사 : " + inBook.publisher +"\n");
}
static void myMusic_Display(Music inMusic)
{
Console.Write("곡명 : " + inMusic.title + "\t");
Console.Write("가수 : " + inMusic.singer+ "\t");
Console.Write("순위 : " + inMusic.rank + "\n");
}
static void myPerson_Display(Person inPerson)
{
Console.Write("이름 : " + inPerson.name + "\t");
Console.Write("관계 : " + inPerson.relation + "\t");
Console.Write("휴대폰번호 : " + inPerson.cellPhone + "\n");
}
}
위와 같이 myInformation dll 파일을 참조하게 한 후 대리자에 클래스 형태로 입력 파라미터를 넘겨서 원하는 작업을 수행할 수 있습니다.
친애하는 학생여러분! 열심히 복습하고 이 코드를 응용해보기 바라며 실력을 쌓아서 좋은 곳에 취업되길 바란다.
'C# > Delegate' 카테고리의 다른 글
| 입력 파라미터로 클래스를 받은 대리자와 dll 사용하기 (0) | 2011/11/02 |
|---|
Windows Phone 7.1 Mango에서 하나의 버튼(Button)을 클릭하면 다른 버튼(Button)을 클릭하는 효과를 주기 위한 방법을 간략히 소개합니다.
기본적으로 Windows Forms에서 처리하는 방법과 거의 비슷합니다.
간단하게 Windows Phone 응용 프로그램 프로젝트를 생성하고 다음과 같이 Button 2개 TextBlock 컨트롤 1개를 도구 상자에서 끌어다 놓습니다.
배치를 완료한 후 Button2, Button1를 클릭하여 다음과 같이 코드를 작성합니다.
private void button2_Click(object sender, RoutedEventArgs e)
{
button1_Click(this, e);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
textBlock1.Foreground=new SolidColorBrush(Colors.Yellow);
textBlock1.Text = "I'm a textBlock.^^";
}
위와 같이 처리해주면 Button2를 클릭했을 때 Button1도 클릭되어 TextBlock의 텍스트를 노란색으로 표시하고 그 Text값을 다음과 같이 표시하게 됩니다.
간단하지만 모르면 어렵고 알면 쉬운 팁이었습니다. 모두들 즐플하세요.
기본적으로 Windows Forms에서 처리하는 방법과 거의 비슷합니다.
간단하게 Windows Phone 응용 프로그램 프로젝트를 생성하고 다음과 같이 Button 2개 TextBlock 컨트롤 1개를 도구 상자에서 끌어다 놓습니다.
배치를 완료한 후 Button2, Button1를 클릭하여 다음과 같이 코드를 작성합니다.
private void button2_Click(object sender, RoutedEventArgs e)
{
button1_Click(this, e);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
textBlock1.Foreground=new SolidColorBrush(Colors.Yellow);
textBlock1.Text = "I'm a textBlock.^^";
}
위와 같이 처리해주면 Button2를 클릭했을 때 Button1도 클릭되어 TextBlock의 텍스트를 노란색으로 표시하고 그 Text값을 다음과 같이 표시하게 됩니다.
간단하지만 모르면 어렵고 알면 쉬운 팁이었습니다. 모두들 즐플하세요.
'Silverlight와 WPF' 카테고리의 다른 글
| Windows phone 7 에서 다른 버튼 클릭하기 (0) | 2011/10/05 |
|---|---|
| Windows phone 7.1 Beta 삭제하기 (0) | 2011/09/02 |
| XAML 코드 작성시 하나의 속성(특성)을 한 줄에 표시되도록 하려면? (0) | 2011/06/11 |

Prev
Rss Feed