|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
C# user input
Ok, this is probably very simple! but how do you get user input from a console window. I've been looking though learning C# and i just cant find anything at all. I was thinking something to do with System.Console or System.IO but
.Mark. |
|
#2
|
|||
|
|||
|
Hey Mark
This is a great tutorial http://www.softsteel.co.uk/tutorials/cSharp/cIndex.html This is also great, a bit more in depth – so some obvious stuff that you’ll need to skim over, but explains some new concepts in a little more depth. http://www.csharp-station.com/Tutorial.aspx This is also great – the M$ one http://msdn.microsoft.com/library/d...rpSpecStart.asp Code:
Console.WriteLine("Enter your name");
string s7 = Console.ReadLine();
Console.WriteLine("Hello, {0}!", s7);
|
|
#3
|
||||
|
||||
|
Thanks Yogi, works perfectly! I'll give the tutorials a good reading a little latter
![]() Mark. |
|
#4
|
|||
|
|||
|
Ok, that was really helpful, but what if i wanted there to be an int value or a number. What is the code for that?
|
|
#5
|
||||
|
||||
|
Always read from the console as a string. Then use Typname.Parse() or Typename.TryParse() to convert that to your desired type. For example, if you want an integer it would be Integer.Parse. A Decimal would be Decimal.Parse. Same for a Datetime. You can also use Convert.ToTypename() for more exotic types.
__________________
Primary Forums: .Net Development, MS-SQL, C Programming VB.Net: It's not your father's Visual Basic. [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers] |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > C# user input |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|