Click to See Complete Forum and Search --> : Console Application (Newb)
JAtkinson
Mar 10th, 2004, 08:27 PM
Ive been coding in VB.net 2003 for awhile and today I decided to buy a book to learn C#. I just finished a console "Hello World" application. In the book, the example shows that after the console displays "Hello World" and the time, it also says "Press any key to continue". In my application (with the same exact code) it just displays the "hello world" and date, and then quits, without giving you time to read it or "press any button". Very newbish question, but does anyone have an idea of why it's doing this?
Thanks,
James
public static void Main(string[] args)
{
// display "Hello World" on the screen
System.Console.WriteLine("Hello World");
// display the current date and time
System.Console.WriteLine("The current date and time is: " + System.DateTime.Now);
}
pvb
Mar 10th, 2004, 08:58 PM
stick this as the last line:
Console.ReadLine()...then it'll wait until you hit the <Enter> key to exit
JAtkinson
Mar 10th, 2004, 09:03 PM
I knew it had to be simple.. and thank you very much.
James
wossname
Mar 11th, 2004, 08:18 AM
also, if you run it from within the IDE (via the debug menu) it will wait at the end of the program even if you don't put Readline in.
pvb
Mar 11th, 2004, 08:46 AM
What settings do you need to make for that to happen? when I hit run from the debug menu it'll close without the ReadLine.
pvb
Mar 11th, 2004, 08:49 AM
never mind, CTRL+F5, start without debugging will do it
JAtkinson
Mar 11th, 2004, 03:04 PM
Originally posted by pvb
What settings do you need to make for that to happen? when I hit run from the debug menu it'll close without the ReadLine.
Yeah, that was the same problem I was having..
BramVandenbon
Mar 29th, 2004, 10:06 AM
another way to solve your problem:
----------------------------------------------
right click on the toolbars and then select "Customize ..."
Then click on the "commands" tab-page. And you'll see a list of buttons to add. You need to look inside the "Debug" folder.
And there you'll find "start without debugging" (the one with the red exclamation mark.)
Then simply drag it to the toolbar, and you'll have this function around without needing your keyboard.
greetings ;-)
CornedBee
Mar 30th, 2004, 03:22 AM
"Without needing your keyboard"??? You always need your keyboard when programming. Get used to hotkeys and shortcuts and put your hands as little on the mouse as possible, you're faster this way.
BramVandenbon
Mar 30th, 2004, 11:44 AM
wow, thank you for your contribution to this thread ... it was very "useful and informing".
On the other hand I would like to add that most programmers who used to work with Visual C++ used this button a lot because it was shown standard.
My comment was only some additional information for those hardcore programmers who made the step from c++ to c#. For newbies this may sound very stupid and useless so I understand your reaction.
No hard feelings :D
CornedBee
Mar 30th, 2004, 11:58 AM
Huh?
You are implying two things in your post. First, that C# is better than C++. Second, that I'm a newbie.
On the second issue you might want to ask some people in the C++ forum what they think.
On the first, I always try to stay fair. I think C++ is far better than C#, but I see them as having different areas of applications, so I do not compare them. (I do, however, compare C# and Java, but I don't want to start a flame war).
And I DO have hard feelings, but I don't let them affect me ;)
BramVandenbon
Mar 30th, 2004, 12:21 PM
hehe
Read my reply over again. I didn't say or imply anything.
:rolleyes: You allready showed your hard feelings when you replied to my first post, and you showed them again with your 2nd post.
Relax :D !!
BTW:
I agree on the Java <> C++ topic, but totally disagree on the C++ <> C# topic. I think you are only comparing compilers when you are saying things like this. C# has a very well structured classes, is easier, can be used on all platforms. I don't see any disadvantage in C# (except for the .NET framework itself maybe) But that's not a matter of languages but a matter of compilers and environments.
I have the feeling you are not familiar with C# yet and are just taking sides of the old stuff, because that's the classic way of seeing things. For people like you microsoft made it possible to implement different languages in the .NET environment :p . So feel free to program in RPG, Cobol or ... C++. Good luck. :wave:
CornedBee
Mar 30th, 2004, 12:45 PM
No, I'm afraid I still have to disagree.
Java is very much like C#. As a matter of fact, it is not possible to distinguish the two without looking closely for tell-tale keywords. The similarities don't end with the syntax. Both are compiled to byte code, both get interpreted and/or JITed by a virtual machine, both have large class libraries shipped with them by default. Both are garbage collected and know only primitives and reference types (C# relaxes on this a bit).
C++ has none of that. It is always (unless you count Managed C++) compiled to native code, has easily distinguishable syntax, a relatively small standard library, real stack variables of all kinds and explicit memory management. It is far more different from C# than Java is.
Believe me, I have used C#. And I have my reasons for preferring Java over it, and disliking Microsoft is not the only one.
And I still say you implied these two things, if maybe involuntarily. Read this sentence carefully.
For newbies this may sound very stupid and useless so I understand your reaction.
This says that you understand my reaction because what you said must seem useless to a newbie. Implies that I am a newbie.
BramVandenbon
Mar 30th, 2004, 01:59 PM
Both are compiled to byte code, both get interpreted and/or JITed by a virtual machine, both have large class libraries shipped with them by default...
See you're just comparing the compilers and environments ... If you use C++ in a .NET framework or VB.NET you'll have the same thing. All those languages are compiled to the same intermediate language. Still the only thing those languages have in common with Java is being a OO language. Just as I said ...
And indeed .NET (but certainly not C#) and java are the same concept. But C# as a language is just improved C++. (Leaving out the pointer stuff and other oldfashioned things). It's Introducing easy new ideas (like properties, the try-catch error handling, very easy inheritance and polymorphism). If you wanted to make a form in C++ it took hours of work. Now it's only a matter of 3 lines of code. So c# is a another step closer to logics! Still the syntax of C# has a lot more in common with C++ than Java.
So you might have used some C#but I only hear you complaining about .NET not about C#. Having a small standard library isn't really a disadvantage neither. It's up to the programmer to choose what to use.
I've seen C# code running very smooth on Linux machines. And linux users hate C++ just as much as C#. And the only reason they do is because it's a microsoft language.
Just to finish of this linux discussing I feel comming up. Linux users always complain about everything. Saying Windows is not stable ... Try putting a heavy user interface on linux and you have the same problem. In fact linux is becomming nothing but a windows clone. Including textwriters, spreadsheets, etc... And at the moment you put too much on your system it crashes. And yeaaaaaah sure linux is open source, this means that your OS-code is unprotected for hackers and written by amateurs. My Windows XP has been running since the first day it was available. And it never crashed even once. Another thing they blame microsoft for is concentrating only about money. Well, let me tell you : all companies are like that. And it's thanks to microsofts way of thinking and building campaigns that PC made it where it is today. So without microsoft we would have no job at all. Still hating microsoft, then why do you use C++ and C#anyway ? This taking-linux-sides is again one of the classic ways of thinking. Seems like you don't have a personal opinion at all ;)
So about the newbie part ... I didn't mean you were a newbie in C++, I was refering to newbies at C#.
CornedBee
Mar 30th, 2004, 02:10 PM
You are bringing up every single issue you could start a flame war about. I'm not gonna be dragged into a discussion about programs that crash when I click on "Open File..."
But see, you call C++ a Microsoft language. It isn't and never was.
You generalize on "Linux users". You complain about me setting C# and the .Net framework equal, then you do the same. (Try making a form in C# with only the classes from the System namespace.)
What is a language other than the compiler, the environment, the capabilities and the available library? And in all of these things C# and Java are much closer than C# and C++.
wey97
Apr 1st, 2004, 01:44 PM
Originally posted by BramVandenbon
And indeed .NET (but certainly not C#) and java are the same concept. But C# as a language is just improved C++.
WRONG
Still the syntax of C# has a lot more in common with C++ than Java.
WRONG
Comparing C++ and C# is like comparing apples and oranges where C# and Java is more like oranges and tangerines ;)
C# was designed from the ground up and has nothing to do with C++ ! (other than C++.NET)
A common theme in C++ is the scope resolution operator (I think that's what it's called.)
If you have a namespace n, class c, and static member s in C++ the notation is n::c::s; but in C# you use n.c.s;
C#'s managed String class couldn't be anything closer to Java's.
In C++ you have .h and .cpp files separating class declaration and definition. C# and Java don't.
CornedBee's already mentioned memory allocation/garbage collection.
There's a lot longer list of differences between C# and C++ and similarities between Java and C#.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.