HowToForums.net Forum Index HowToForums.net
An Open Source of Knowledge
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IFormattable add

 
Post new topic   Reply to topic    HowToForums.net Forum Index -> OpenU Technical Discussion
View previous topic :: View next topic  
Author Message
sharonshmuelfeldman



Joined: 29 Jul 2009
Posts: 8

PostPosted: Thu Aug 06, 2009 7:47 pm    Post subject: IFormattable add Reply with quote

//1) add IFormattable to Employee

public class Employee : IFormattable

//2) add : the new ToString() //asuming you have a Status Property Defined Already

public string ToString(string format, IFormatProvider provider)
{
if (String.IsNullOrEmpty(format))
return Status.ToString();

switch (format.ToUpperInvariant())
{

case "F":
return "*"+Status.ToString();

default:
throw new FormatException(String.Format("The {0} format string is not supported.", format));
}
}

//3) in Main do :
foreach(Employee p in personal)
{
Console.WriteLine("{0:F}",p);
}
________
Synthetic Weed
Back to top
Display posts from previous:   
Post new topic   Reply to topic    HowToForums.net Forum Index -> OpenU Technical Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group