New Posts  All Forums:Forum Nav:

C# basic program help? - Page 2

post #11 of 14
Quote:
Originally Posted by kidshenlong View Post
Thanks for the help guys. Would've used a switch statement but the exercise specifically asked for the use of if statements. Thanks for the help anyway... I imagine I'll be posting a lot more over the next few weeks Rep +
Not that overclockers is a bad site, but you might want to use http://stackoverflow.com/ for programming questions, a very good site!
post #12 of 14
IF statements....

Take a look at the Dictionary class, it might seem daunting at first, but it's a better way to go about things.

Code:
private Dictionary<int, string> Labels = new Dictionary<int,string>()
{
    {1, "The day is Monday!"},
    {2, "The day is Tuesday!"},
    {3, "The day is Wednesday!"},
    {4, "The day is Thursday!"},
    {5, "The day is Friday!"},
    {6, "The day is Saturday!"},
    {7, "The day is Sunday!"},
};

public string GetLabelText(int day)
{
     if (Labels.ContainsKey(day))
        return Labels[day];

     return "Mad day";
}
EDIT : Oh. You've since posted to say they want you to use IF statements.
post #13 of 14
Quote:
Originally Posted by SafeKlok View Post
IF statements....

Take a look at the Dictionary class, it might seem daunting at first, but it's a better way to go about things.

Code:
private Dictionary<int, string> Labels = new Dictionary<int,string>()
{
    {1, "The day is Monday!"},
    {2, "The day is Tuesday!"},
    {3, "The day is Wednesday!"},
    {4, "The day is Thursday!"},
    {5, "The day is Friday!"},
    {6, "The day is Saturday!"},
    {7, "The day is Sunday!"},
};

public string GetLabelText(int day)
{
     if (Labels.ContainsKey(day))
        return Labels[day];

     return "Mad day";
}
EDIT : Oh. You've since posted to say they want you to use IF statements.
lol, if all else fails, bust out the indexed data structures and use the contains method.
Malignance
(24 items)
 
  
CPUMotherboardGraphicsRAM
i5-2500K Asus P8Z68-V eVGA GTX670 FTW 16GB Mushkin DDR3-2100 1.5V 
Hard DriveHard DriveHard DriveOptical Drive
2 x 128GB Crucial M4 2 x 1TB Samsung F3 RAID0 1.5TB Seagate Asus 22X DVDRW 
CoolingOSMonitorMonitor
Noctua NH-D14 Windows 7 Ultimate 64-bit Dell Ultrasharp U2410 Asus ProArt PA248Q 
KeyboardPowerCaseMouse
Rosewill RK-9000BR PCP&P Silencer MKIII 600W Lian Li PC-A05NB Logitech G500 
Mouse PadAudioAudioAudio
Rocketfish Dual Sided Asus Xonar Essence STX Infinity Primus P153 | Dayton DTA-120 Amplifier... Shure SRH840 
AudioAudioAudio
Audio Technica ATH-AD700X Objective DAC Audio-Technica ATR2500-USB 
  hide details  
Reply
Malignance
(24 items)
 
  
CPUMotherboardGraphicsRAM
i5-2500K Asus P8Z68-V eVGA GTX670 FTW 16GB Mushkin DDR3-2100 1.5V 
Hard DriveHard DriveHard DriveOptical Drive
2 x 128GB Crucial M4 2 x 1TB Samsung F3 RAID0 1.5TB Seagate Asus 22X DVDRW 
CoolingOSMonitorMonitor
Noctua NH-D14 Windows 7 Ultimate 64-bit Dell Ultrasharp U2410 Asus ProArt PA248Q 
KeyboardPowerCaseMouse
Rosewill RK-9000BR PCP&P Silencer MKIII 600W Lian Li PC-A05NB Logitech G500 
Mouse PadAudioAudioAudio
Rocketfish Dual Sided Asus Xonar Essence STX Infinity Primus P153 | Dayton DTA-120 Amplifier... Shure SRH840 
AudioAudioAudio
Audio Technica ATH-AD700X Objective DAC Audio-Technica ATR2500-USB 
  hide details  
Reply
post #14 of 14
Quote:
Originally Posted by RallyMaster View Post
lol, if all else fails, bust out the indexed data structures and use the contains method.
Haha, yup.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming