this reference from msdn blog
using
System;using
System.Collections.Generic;using
System.Text;using
System.IO;namespace
ConsoleApplication1{
class Program
{
[
Flags]enum DisplayUserOptions
{
Email = 0x1,
PhoneNumber = 0x2,
Both = (Email | PhoneNumber),
}
static void Main(string[] args)
{
User user=new User();
TextWriter stream=null;
//cara 1
DisplayUser1(user,
Console.Out, true /*displayEmail*/, false /*displayPhoneNumber*/);//cara 2
DisplayUser2(user, stream,
DisplayUserOptions.Email);//cara 3
//More readable but much more verbose(panjang kata2nya)
DisplayUserOption options = new DisplayUserOption();
options.Email =
true;options.PhoneNumber =
false;DisplayUser3(user, stream,options);
//Cara 4 di C#3.0 bisa pake object initializers
DisplayUser3(user,
Console.Out, new DisplayUserOption { Email = true, PhoneNumber = false });}
static void DisplayUser1(User user, TextWriter stream, bool displayEmail, bool displayPhoneNumber)
{
}
static void DisplayUser2(User user, TextWriter stream, DisplayUserOptions options)
{ }
static void DisplayUser3(User user, TextWriter stream, DisplayUserOption options)
{ }
}
class User
{ }
struct DisplayUserOption
{
public bool Email;
public bool PhoneNumber;
}
}
Tidak ada komentar:
Posting Komentar