Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › [C#] if statements with methods?
New Posts  All Forums:Forum Nav:

[C#] if statements with methods?

post #1 of 14
Thread Starter 
Basically I have this method...

Code:
 private bool isBig (int y)
        {
            int dogHeight = y;
            if(dogHeight <50)
            {
                return false;
              
            }
            else
            {

                return true;
            }
        }
and I have this method:
Code:
  public string GetSpeech()
        {
            
                dogSpeech = "Hello. I am a " + breed + ". " + barkSound;
                return dogSpeech;

            }
I can't figure it out for some reason probably because it's so late over here lol. Anyway depending on the returned boolean true or false I wanted a different response... Like this...

Code:
 public string GetSpeech()
        {
            if (isBig == true)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am big.  " + barkSound;
                return dogSpeech;

            }
            if (isBig = false)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am small. " + barkSound;
                return dogSpeech;

            }
        
        }
But that's not working... Help?

Thanks
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
post #2 of 14
if (isBig == true)
{

dogSpeech = "Hello. I am a " + breed + ". I am big. " + barkSound;
return dogSpeech;

}
if (isBig = false)


Look at the =.
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
post #3 of 14
Code:
 public string GetSpeech()
        {
            if (isBig(theDog) == true)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am big.  " + barkSound;
                return dogSpeech;

            }
            if (isBig(theDog) == false)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am small. " + barkSound;
                return dogSpeech;

            }
        
        }
isBig() is a function
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #4 of 14
I don't know C# but it would be something like this in C++


Code:
if ( isBig(y) )
{
        // code
}
if ( !isBig(y) )
{
        // code
}
Ziltoid
(14 items)
 
Exo x352
(6 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i5 2500k @ 4.1GHz ASUS P8Z68-v PRO XFX 9500GT 2x4GB GSkill Ripjaws x 1600MHz 
Hard DriveOSMonitorMonitor
OCZ Vertex 3 60GB Windows 8 LG FLATRON W1943SE LG 23EA53 
PowerCase
Sentey GSP750-SM Coolermaster 690 II 
CPUMotherboardGraphicsRAM
Intel Atom N455 ECS E11IS1 GMA 3150 1 GB 667 MHz 
Hard DriveOS
Fujitsu 160 GB 5200 rpm Lubuntu 
  hide details  
Reply
Ziltoid
(14 items)
 
Exo x352
(6 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i5 2500k @ 4.1GHz ASUS P8Z68-v PRO XFX 9500GT 2x4GB GSkill Ripjaws x 1600MHz 
Hard DriveOSMonitorMonitor
OCZ Vertex 3 60GB Windows 8 LG FLATRON W1943SE LG 23EA53 
PowerCase
Sentey GSP750-SM Coolermaster 690 II 
CPUMotherboardGraphicsRAM
Intel Atom N455 ECS E11IS1 GMA 3150 1 GB 667 MHz 
Hard DriveOS
Fujitsu 160 GB 5200 rpm Lubuntu 
  hide details  
Reply
post #5 of 14
Thread Starter 
Quote:
Originally Posted by andrewmchugh View Post
if (isBig == true)
{

dogSpeech = "Hello. I am a " + breed + ". I am big. " + barkSound;
return dogSpeech;

}
if (isBig = false)


Look at the =.
Nope it's not that. That was just a copy paste type

Quote:
Originally Posted by FiX View Post
Code:
 public string GetSpeech()
        {
            if (isBig(theDog) == true)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am big.  " + barkSound;
                return dogSpeech;

            }
            if (isBig(theDog) == false)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am small. " + barkSound;
                return dogSpeech;

            }
        
        }
isBig() is a function
Figured as much lol So what would I have to do instead?

Quote:
Originally Posted by Joakitex View Post
I don't know C# but it would be something like this in C++


Code:
if ( isBig(y) )
{
        // code
}
if ( !isBig(y) )
{
        // code
}
Hmmm tried a similar thing in c# but nothing
Edited by kidshenlong - 10/23/11 at 5:32pm
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
post #6 of 14
Why dont you do..
Code:
if ( isBig(peram) )
{
        ..
}else
{
      ..
}
Quote:
Code:
 private bool isBig (int y)
        {
            int dogHeight = y;
            if(dogHeight <50)
            {
And thats daft..
Code:
 private bool isBig (int dogHeight0
        {
            if(dogHeight <50)
            {

Edited by andrewmchugh - 10/23/11 at 5:35pm
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
post #7 of 14
Code:
 public string GetSpeech(int theDog/*pass the dogs size as an integer*/)
        {
            if (isBig(theDog)/*if its true then it will know*/)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am big.  " + barkSound;
                return dogSpeech;

            }
            else/*no need for the if, boolean logic, true or false*/
            {

                dogSpeech = "Hello. I am a " + breed + ". I am small. " + barkSound;
                return dogSpeech;

            }
        
        }
This code assumes barkSound is a global variable
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #8 of 14
Thread Starter 
No luck
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
post #9 of 14
Thread Starter 
Quote:
Originally Posted by FiX View Post
Code:
 public string GetSpeech(int theDog/*pass the dogs size as an integer*/)
        {
            if (isBig(theDog)/*if its true then it will know*/)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am big.  " + barkSound;
                return dogSpeech;

            }
            else/*no need for the if, boolean logic, true or false*/
            {

                dogSpeech = "Hello. I am a " + breed + ". I am small. " + barkSound;
                return dogSpeech;

            }
        
        }
This code assumes barkSound is a global variable
woops just saw this now so going to try.
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
post #10 of 14
Thread Starter 
Quote:
Originally Posted by FiX View Post
Code:
 public string GetSpeech(int theDog/*pass the dogs size as an integer*/)
        {
            if (isBig(theDog)/*if its true then it will know*/)
            {

                dogSpeech = "Hello. I am a " + breed + ". I am big.  " + barkSound;
                return dogSpeech;

            }
            else/*no need for the if, boolean logic, true or false*/
            {

                dogSpeech = "Hello. I am a " + breed + ". I am small. " + barkSound;
                return dogSpeech;

            }
        
        }
This code assumes barkSound is a global variable
Sorry, I haven't been to sleep in a while and this is just confusing the hell out of me. Could you break it down a bit more? I'm following a spec so I'm not too sure if I can do the suggestion above.

Quote:
d)In the class Dog, add a private method called IsBig that returns a Boolean and takes a parameter of type integer. If that parameter is <50, the method should return false. Otherwise it should return true


e)In the class Dog, change the method GetSpeech so

ousing the method IsBig created in point (d) checks if the dog is big or not.
oit returns all details about the dog (including dogHeight , dogColour). Also, the dog should state if it is big or not.
 Hint: It cannot return the noOfLegs as it is a static variable
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
Dark Star
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 - Currently Overclocking ;) Gigabyte GA-EP45-UD3P HD 6950 OCZ Blade LC DDR2 PC29200 4GB (GOT) 
Hard DriveOSMonitorKeyboard
640GB for Storage and OCZ Vertex 2e 60GB Windows 7 Ultimate-Signature Edition 3 x 22" -BenQ G2222HDL Logitech G15 
PowerCaseMouse
Corsair TX850 HAF 932 Logitech G500 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › [C#] if statements with methods?