Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: Help! C# [CODE]

  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Help! C# [CODE]

    I got a book to learn C# coding and it directed me to do a program thing called "Hello World" i entered the code correctly but when i run the debugger the console pops up and says "Hello. My name is Inigo Montoya." as i directed it to, but the console only pops up for a few milliseconds and then closes. I thought that maybe a experienced person could help. Here is the Code i entered:


    class HelloWorld
    {
    static void Main()
    {
    System.Console.WriteLine("Hello. My name is Inigo Montoya.");
    }
    }

    I used the correct format altho in the post the codes spaces might be off. O and im also using "Microsoft visual studios custom C#" to do the coding and what not.
    Last edited by jameswray50; 12-21-2011 at 07:59 PM.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,662
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    So, and why are you posting this in the HTML/CSS forum then?
    Moved to the correct forum.

  • #3
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by jameswray50 View Post
    I got a book to learn C# coding and it directed me to do a program thing called "Hello World" i entered the code correctly but when i run the debugger the console pops up and says "Hello. My name is Inigo Montoya." as i directed it to, but the console only pops up for a few milliseconds and then closes. I thought that maybe a experienced person could help. Here is the Code i entered:


    class HelloWorld
    {
    static void Main()
    {
    System.Console.WriteLine("Hello. My name is Inigo Montoya.");
    }
    }

    I used the correct format altho in the post the codes spaces might be off. O and im also using "Microsoft visual studios custom C#" to do the coding and what not.
    I only does that in Visual studios. To stop it, just type: System.Console.ReadLine(); after your WriteLine
    Last edited by melloorr; 12-21-2011 at 08:39 PM.

  • #4
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I'm a little confuzed... First I'm new to all this so the **** I'm getting from you guys (intentional or not) is very annoying while I'm trying to learn this stuff.

    So based on what "melloorr" said i was un-able to figure that out... Do you think i completed this lesson in my book "hello World" console? i can get it to run just for a millisecond.
    Last edited by jameswray50; 12-21-2011 at 08:57 PM.

  • #5
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by jameswray50 View Post
    Im a little confuzed... First im new to all this so the **** im getting from you guys (intentional or not) is very annoying while im trying to learn this stuff.

    So based on what "melloorr" said i was un-abble to figgure that out... Do you think i compleated this lesson in my book "hello World" consol? i can get it to run just for a millisecound.
    Code:
    class HelloWorld
    {
    static void Main()
    {
    System.Console.WriteLine("Hello. My name is Inigo Montoya.");
    System.Console.ReadLine();
    }
    }
    That should work, so you exit by pressing enter

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,739
    Thanks
    41
    Thanked 191 Times in 190 Posts
    what melloorr posted is a viable solution. but you could simplify it to this...
    Code:
    using System;
    
    namespace YourNameSpaceHere
    
    class Hello
    {
      static void WriteHello()
      {
         Console.WriteLine("Hello World")
         Console.ReadLine();
      }
    }
    now let's go through and see why it is only open/up/running for a few milliseconds... Look at the function... the very first line is write something... program goes "ok- I'll write what you told me to in code" ... after program does this it moves on... so now the program says "now what?" ... well there is nothing there so the program is done and closes.... now if this were more than a "main program" eg it was a function to display/set something this part would happen and set those variables... so you could have something like this
    Code:
    class MyProgram
    {
      static void Main()
      {
        MyProgram _start = new MyProgram();
        _start.hello();
        Console.ReadLine();
      }
    
      public void hello()
      {
        Console.WriteLine("Hello World!");
      }
    }
    what happens now is the program drops into the Main and creates an object of type class and then calls that objects function hello which writes the output... I assume that will come later in the book though

    I do not know what melloorr's first post meant... if you were to compile that code and run anywhere (ie not just in Visual Studio) it would do the same thing no matter what- there is nothing more to the program... If melloorr meant he/she uses VS then idk why he/she said it at all... as to your comment
    First I'm new to all this so the **** I'm getting from you guys (intentional or not) is very annoying while I'm trying to learn this stuff.
    I saw nothing offensive or "giving ****" ... VIP was just pointing out you posted in wrong place as to not confuse other members and also to make sure you get an answer... You may read this as giving you **** but the intention is not... I do a lot of C# and (at least I feel) I help a lot of ppl here as best I can- I will not help you if you spaz out and you may get infractions/banned if you do... calm down some anyone who bashes newbies gets infractions pretty quick- we are all under the understanding this is a learning based environment and is targeted as such- thus we all understand the need to help and not flame others and it is quickly addressed by the mods.

    Post back if you do not understand the resolution melloorr posted (or mine which is essentially the same thing) and I can try to explain it better... if you are working through things in the book and post here make sure it is a new thread for new issues and also (if you could) mark them as resolved when you get it "down"/"answered" (to do this click edit on your very first post in thread and then click go advanced there is a drop down list that you can choose from in the upper left corner)... Again I do C# and am very active here so I can help you as best as possible (idk how many C# coders are here/active)... Welcome and happy posting

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #7
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,739
    Thanks
    41
    Thanked 191 Times in 190 Posts
    Edit: Posted reply twice somehow deleted so wasn't so "big"
    Last edited by alykins; 12-22-2011 at 12:59 AM. Reason: double post

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #8
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by alykins View Post
    I do not know what melloorr's first post meant... if you were to compile that code and run anywhere (ie not just in Visual Studio) it would do the same thing no matter what- there is nothing more to the program... If melloorr meant he/she uses VS then idk why he/she said it at all... as to your comment
    I just meant that, in Visual Studio, if you debug, then it will go off as soon as it has wrote the line, unless you have something to actually stop it. But if you actually RUN it, then it will stay on and say 'Press Enter to continue...' (or something like that)

    I didn't want to make it too complicated for him, so I was a bit vague, but as it happens, it wasn't the best idea. :/
    Last edited by melloorr; 12-22-2011 at 02:04 AM.

  • #9
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,739
    Thanks
    41
    Thanked 191 Times in 190 Posts
    Quote Originally Posted by melloorr View Post
    I just meant that, in Visual Studio, if you debug, then it will go off as soon as it has wrote the line, unless you have something to actually stop it. But if you actually RUN it, then it will stay on and say 'Press Enter to continue...' (or something like that)
    no- if you run it outside of VS it would also end... the only way to stop it is to add something like what you added (Console.ReadLine() or some other method to make it "sit" there... once the program has reached it's end it really has "reached it's end" ... if you would build/publish the original posted code in release mode it would do the same thing, start->throw that message to the console-> end

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #10
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Well this is what I got when I ran my code without debugging:



    And as you can see, it has nothing to stop it from exiting

    EDIT
    As it happens you are right, I just ran the .exe and it went off. Suppose it only stops at the end if you run without debugging. But to be fair, I have never built a .exe before now, and I haven't coded c# for a good few months, so I have forgotten most of it :/
    Last edited by melloorr; 12-22-2011 at 04:08 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •