PDA

View Full Version : Having trouble getting started with C#



ratcheer
April 18th, 2012, 04:50 PM
I am a total newbie with C#, but I am an experienced programmer since the early 1970's. I am trying to learn C# in order to help my wife as she learns it at her job. But, I am having trouble with the tiniest programs from the tutorial I am trying to follow.

My IDE is MonoDevelop 2.6. The first tutorial example, Hello World, compiles and runs perfectly. However, the second program demonstrates a way to pause and accept input from the user. The program compiles and runs, but it skips right past the pause for input and completes, having accepted a null input value that I did not enter. Is the tutorial wrong, did I do something wrong, or is this a bug in MonoDevelop?

Here is the code in question, with the statement that is supposed to pause for input highlighted:


string firstName = "John";
string lastName = "Doe";

Console.WriteLine("Name: " + firstName + " " + lastName);

Console.WriteLine("Please enter a new first name:");
firstName = Console.ReadLine();

Console.WriteLine("New name: " + firstName + " " + lastName);

Console.ReadLine();Tim

11jmb
April 18th, 2012, 06:26 PM
This certianly seems like a bug in Mono. Having never used Mono, I can't tell you for sure, but I've had no problem reading from command line using Console.ReadLine() in VS C# projects

ratcheer
April 18th, 2012, 06:54 PM
Thanks, @11jmb. That is my thought, too. The program is just too simple for it to be a program error. And the tutorial so carefully explained about the ReadLine statement waiting for input, I don't see how that can be wrong, either.

So, my MonoDevelop version 2.6 is from the Ubuntu repos. But the current version is 2.8. I wonder if I could find that and upgrade?

Tim

ratcheer
April 18th, 2012, 07:56 PM
Ok, I figured out how to compile at the command line. Everything I read says use gmcs, but the command with my version of C# is dmcs.

Anyway, when done this way, the program runs as expected, waiting for and accepting user input. Either something is wrong with MonoDevelop, or there is something I don't know about how to use it.

Tim

Newbie2910
April 19th, 2012, 01:21 AM
Tim, I cannot give you an answer to your specific question but I have used MonoDevelop for several years and like it a lot.

I also use VisualC# (the freebie version) and like it as well.

Nice thing is, MonoDevelop will build and run any VC# project unchanged. Is there a reason you are starting with console apps? I would start with windowed apps and event-driven programming, much easier and the environment makes it simple to tie GUI events into code.

If you create a Windows Forms app using VC# and copy the project to MonoDevelop, it will run unchanged.

You will also find that you can run WPF apps on Linux unchanged using VirtualBox (which I do). I love WPF.

venomenus
April 19th, 2012, 08:15 AM
Hi,

Just to add to this, We heavily run C# applications at work in a cross platform environment, The best way I've found to keep everyone running the same mono version in Linux is by adding the badgerports repository located here http://badgerports.org/
monodevelop is also included in this.

Hope this helps!

ratcheer
April 19th, 2012, 01:17 PM
Thanks for the tip, @venomenus. I will take a look.

Tim

ratcheer
April 19th, 2012, 02:11 PM
I have added badgerports to my system and upgraded to Mono 2.10 and MonoDevelop 2.8. This is excellent, but it does not resolve my problem. I have a feeling that I am not using MonoDevelop properly.

Tim

mehaga
April 20th, 2012, 12:55 PM
Just copy-pasted your code into a new Monodevelop project. Runs exactly as expected. I don't know if it makes any difference, but let me ask, did you create your project as "Console Application"?

ratcheer
April 20th, 2012, 01:49 PM
Thanks, @vekaz. I will try it that way. I have just been opening a c-sharp source file and running it in the console window. Or even just pasting in code from the tutorial. I thought that running these simple programs would be easy enough that way, but maybe they have to be part of a project. I guess I could call the prohect "Tutorial Examples" or something.

Tim

directhex
April 20th, 2012, 11:58 PM
MonoDevelop's terminal emulator, VTE#, does not support input.

You need to configure your project to execute on an external shell, not the built-in terminal.

ratcheer
April 21st, 2012, 02:17 AM
MonoDevelop's terminal emulator, VTE#, does not support input.

You need to configure your project to execute on an external shell, not the built-in terminal.

Thank you very much. I wonder why they cannot just make that plain in the documentation? Good grief.

Tim