Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [C#] A Few Basic Questions
New Posts  All Forums:Forum Nav:

[C#] A Few Basic Questions

post #1 of 7
Thread Starter 
I'm trying to teach myself C#, and I'm thinking rewriting all my old command line C++ programs in C# would help a bit. I just need to know a few things.

What's the equivalent of...
  • cin >> variable; variable = System.Console.ReadLine();
  • fout << variable;
  • fin >> variable;
  • system("command");

Edited by mrtn400 - 7/6/08 at 6:47pm
Cataclysm
(20 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-EP45-UD3P Rev. 1.0 Sapphire 4850 4x 2GB DDR2-1066 
Hard DriveHard DriveOptical DriveCooling
WD1600AAJS Random IDE Sony DVD Burner Tuniq Tower 120 
CoolingCoolingCoolingOS
6x 120mm Scythe SY1225SL12SH Fans Thermalright T-RAD2 2x 92mm Scythe DFS922512M-PWM Fans Windows 7 Ultimate x64 SP1 
MonitorMonitorKeyboardPower
Acer 19" @ 1400x900 Sceptre 19" @ 1280x1024 Cherry G81-7000LPAUS-2 (MY Switches) Corsair 650TX 
CaseMouseMouse PadAudio
Antec 900 Razer Diamondback 3G A black one with a cat in a hammock Asus Xonar D1 
  hide details  
Reply
Cataclysm
(20 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-EP45-UD3P Rev. 1.0 Sapphire 4850 4x 2GB DDR2-1066 
Hard DriveHard DriveOptical DriveCooling
WD1600AAJS Random IDE Sony DVD Burner Tuniq Tower 120 
CoolingCoolingCoolingOS
6x 120mm Scythe SY1225SL12SH Fans Thermalright T-RAD2 2x 92mm Scythe DFS922512M-PWM Fans Windows 7 Ultimate x64 SP1 
MonitorMonitorKeyboardPower
Acer 19" @ 1400x900 Sceptre 19" @ 1280x1024 Cherry G81-7000LPAUS-2 (MY Switches) Corsair 650TX 
CaseMouseMouse PadAudio
Antec 900 Razer Diamondback 3G A black one with a cat in a hammock Asus Xonar D1 
  hide details  
Reply
post #2 of 7
Thread Starter 
I figured out what the first one was. Also I added one more.
Cataclysm
(20 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-EP45-UD3P Rev. 1.0 Sapphire 4850 4x 2GB DDR2-1066 
Hard DriveHard DriveOptical DriveCooling
WD1600AAJS Random IDE Sony DVD Burner Tuniq Tower 120 
CoolingCoolingCoolingOS
6x 120mm Scythe SY1225SL12SH Fans Thermalright T-RAD2 2x 92mm Scythe DFS922512M-PWM Fans Windows 7 Ultimate x64 SP1 
MonitorMonitorKeyboardPower
Acer 19" @ 1400x900 Sceptre 19" @ 1280x1024 Cherry G81-7000LPAUS-2 (MY Switches) Corsair 650TX 
CaseMouseMouse PadAudio
Antec 900 Razer Diamondback 3G A black one with a cat in a hammock Asus Xonar D1 
  hide details  
Reply
Cataclysm
(20 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-EP45-UD3P Rev. 1.0 Sapphire 4850 4x 2GB DDR2-1066 
Hard DriveHard DriveOptical DriveCooling
WD1600AAJS Random IDE Sony DVD Burner Tuniq Tower 120 
CoolingCoolingCoolingOS
6x 120mm Scythe SY1225SL12SH Fans Thermalright T-RAD2 2x 92mm Scythe DFS922512M-PWM Fans Windows 7 Ultimate x64 SP1 
MonitorMonitorKeyboardPower
Acer 19" @ 1400x900 Sceptre 19" @ 1280x1024 Cherry G81-7000LPAUS-2 (MY Switches) Corsair 650TX 
CaseMouseMouse PadAudio
Antec 900 Razer Diamondback 3G A black one with a cat in a hammock Asus Xonar D1 
  hide details  
Reply
post #3 of 7
for reading and writing from files check out http://www.devhood.com/Tutorials/tut...utorial_id=400

That's all I can help with I have been coding in C# for 2 weeks now.
post #4 of 7
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
3800x2 DFI NF4 SLI-D HD4850 2gb GSkill ZX 
Hard DriveOSMonitorPower
6+TB of insanity XP Pro L2410NM + DYLM24D6 Corsair 750TX 
CaseMouse
Rocketfish MX 510 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
3800x2 DFI NF4 SLI-D HD4850 2gb GSkill ZX 
Hard DriveOSMonitorPower
6+TB of insanity XP Pro L2410NM + DYLM24D6 Corsair 750TX 
CaseMouse
Rocketfish MX 510 
  hide details  
Reply
post #5 of 7
To read input, you could do something like this:

Quote:
string someValue = int.Parse(Console.ReadLine());
Then to put it out on the console:

Quote:
Console.WriteLine(someValue);
Let me know how that works out for ya.

I think, if you are using MS VS, it should autocomplete for you. Everything you are trying to do is in system.console. You just need to get the syntax right.


EDIT: Important to note that if you try and input anything but a legitimate integer (whole number), it will throw an exception. To get around this, use "TryParse", or create a Try-Catch block (probably a little overkill) to catch the exception and throw an error.
Edited by killnine - 7/6/08 at 7:11pm
    
CPUMotherboardGraphicsRAM
Intel Core i7 920 @ 4Ghz Rampage II GENE PNY GTX 680 G.Skill Sniper (12GB) 
Hard DriveOptical DriveCoolingOS
Seagate Momentus XT SATA Optical Drive Kuhler 920 Windows 7 Ultimate 
MonitorKeyboardPowerCase
Dell U2410 Logitech G11  Silverstone ST75 750W Antec Mini P180B 
MouseMouse PadOther
Logitech MX518 Steelpad G19 Gaming Headset 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel Core i7 920 @ 4Ghz Rampage II GENE PNY GTX 680 G.Skill Sniper (12GB) 
Hard DriveOptical DriveCoolingOS
Seagate Momentus XT SATA Optical Drive Kuhler 920 Windows 7 Ultimate 
MonitorKeyboardPowerCase
Dell U2410 Logitech G11  Silverstone ST75 750W Antec Mini P180B 
MouseMouse PadOther
Logitech MX518 Steelpad G19 Gaming Headset 
  hide details  
Reply
post #6 of 7
Thread Starter 
Quote:
Originally Posted by vgplayer View Post
for reading and writing from files check out http://www.devhood.com/Tutorials/tut...utorial_id=400

That's all I can help with I have been coding in C# for 2 weeks now.
Quote:
Originally Posted by killnine View Post
To read input, you could do something like this:



Then to put it out on the console:



Let me know how that works out for ya.

I think, if you are using MS VS, it should autocomplete for you. Everything you are trying to do is in system.console. You just need to get the syntax right.


EDIT: Important to note that if you try and input anything but a legitimate integer (whole number), it will throw an exception. To get around this, use "TryParse", or create a Try-Catch block (probably a little overkill) to catch the exception and throw an error.
Sweet.

That's answers to everything.

+Rep to all of you.
Cataclysm
(20 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-EP45-UD3P Rev. 1.0 Sapphire 4850 4x 2GB DDR2-1066 
Hard DriveHard DriveOptical DriveCooling
WD1600AAJS Random IDE Sony DVD Burner Tuniq Tower 120 
CoolingCoolingCoolingOS
6x 120mm Scythe SY1225SL12SH Fans Thermalright T-RAD2 2x 92mm Scythe DFS922512M-PWM Fans Windows 7 Ultimate x64 SP1 
MonitorMonitorKeyboardPower
Acer 19" @ 1400x900 Sceptre 19" @ 1280x1024 Cherry G81-7000LPAUS-2 (MY Switches) Corsair 650TX 
CaseMouseMouse PadAudio
Antec 900 Razer Diamondback 3G A black one with a cat in a hammock Asus Xonar D1 
  hide details  
Reply
Cataclysm
(20 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-EP45-UD3P Rev. 1.0 Sapphire 4850 4x 2GB DDR2-1066 
Hard DriveHard DriveOptical DriveCooling
WD1600AAJS Random IDE Sony DVD Burner Tuniq Tower 120 
CoolingCoolingCoolingOS
6x 120mm Scythe SY1225SL12SH Fans Thermalright T-RAD2 2x 92mm Scythe DFS922512M-PWM Fans Windows 7 Ultimate x64 SP1 
MonitorMonitorKeyboardPower
Acer 19" @ 1400x900 Sceptre 19" @ 1280x1024 Cherry G81-7000LPAUS-2 (MY Switches) Corsair 650TX 
CaseMouseMouse PadAudio
Antec 900 Razer Diamondback 3G A black one with a cat in a hammock Asus Xonar D1 
  hide details  
Reply
post #7 of 7
Quote:
string someValue = int.Parse(Console.ReadLine());
The Int.Parse (and Double.Parse and etc..) functions only need to be used to convert a string to a number (or whatever else).
What you're doing there is setting a string (someValue) to an integer value.. not sure if the compiler would complain, and it might work if the language implicitly converts the integer back to a string, but that's a pointless conversion.

The proper method was stated above ( string myString = Console.Readline() ). Proper usage of the Int.Parse method looks like this:
Quote:
int inputNum = Int.Parse(Console.Readline());
Monster v2
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-P35-DS3L HD 4850 6GB Crucial Ballistix 
Hard DriveOSMonitorKeyboard
WD 320GB Windows 7 Ultimate (64bit) 2x Acer 22" WS Logitech g15 
PowerCaseMouse
OCZ 700W Gigabyte 3D aurora Logitech Mx510 
  hide details  
Reply
Monster v2
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 GA-P35-DS3L HD 4850 6GB Crucial Ballistix 
Hard DriveOSMonitorKeyboard
WD 320GB Windows 7 Ultimate (64bit) 2x Acer 22" WS Logitech g15 
PowerCaseMouse
OCZ 700W Gigabyte 3D aurora Logitech Mx510 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [C#] A Few Basic Questions