CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Jun 2012
    Location
    Pennsylvania
    Posts
    10

    Problem with getting output in C#

    I know maybe my question is kind of silly but I am currently doing a method in a big project so I tried to make a new file inside this project to test for my method. But my problem is I can not get the output of this program. Is there any one can give me suggestion. I am already did many times with C++ but I am totally newbie with C# so I have big trouble in C#.

  2. #2
    Join Date
    Jul 2005
    Location
    Louisville, KY
    Posts
    201

    Re: Problem with getting output in C#

    Are you just trying to create a text file with some output?

    Can you please expand on what you're doing?

    Thanks,
    Quinn

  3. #3
    Join Date
    Jun 2012
    Location
    Pennsylvania
    Posts
    10

    Re: Problem with getting output in C#

    I am just basiclly want to separate the words from a string which was apart by the ',' for example this string " 12,sd,123" . and the output is 3 ( for three words 12 , sd and 123 .
    But my problem is I eventually can not get the output like "Helloworld" by
    Console.WriteLine("Helloworld").

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Problem with getting output in C#

    You could use the .Split() method to seperate the string then use .Length on the resulting array to find the number of elements.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jun 2012
    Location
    Pennsylvania
    Posts
    10

    Re: Problem with getting output in C#

    Yeah , I already finished my code but I can not get the output . I mean eventually helloworld I can not write out

  6. #6
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Problem with getting output in C#

    And, when you say "can not get the output" what do you exactly mean by that? The console window doesn't show (or it shows very briefly)? It shows, but nothing's on it? It shows the wrong output? What?
    How are you running your app? With or without debugging (F5 or Ctrl+F5)?
    Did you make a console application project, or a windows forms project (or something else)?
    You've dealt with console apps in C++ before?

  7. #7
    Join Date
    Jun 2012
    Location
    Pennsylvania
    Posts
    10

    Re: Problem with getting output in C#

    yeah the console window doesn't show, I tried to run by both F5 and Ctrl+ F5 . I think it is console application project .
    For C++, I think no ..

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Problem with getting output in C#

    Quote Originally Posted by itamsvtd View Post
    I think it is console application project .
    For C++, I think no ..
    Find out for sure what type of project you have. Right click on the project, choose properties, and see the output type in the application tab. It should be set to "Console Application".

  9. #9
    Join Date
    Jun 2012
    Location
    Pennsylvania
    Posts
    10

    Re: Problem with getting output in C#

    yeah it is console application, I start a new project and I always get this error Error 1 Program 'c:\users...\obj\x86\Debug\Project2.exe' does not contain a static 'Main' method suitable for an entry point Project2 . Do you know how to fix this error ?

  10. #10
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Problem with getting output in C#

    OK. The Main method is the entry point to your application - so it should always be there? Could you verify it is in the code? Should be in Program.cs. You didn't delete it, did you?
    If not, then something's off - attach the project here in that case (if you don't see the full-featured message editor, click "Go Advanced").

    You can also try to create a completely new console application project in a new folder with a new name, and see if it works. Also, are you using Visual Studio?

  11. #11
    Join Date
    Jun 2012
    Location
    Pennsylvania
    Posts
    10

    Re: Problem with getting output in C#

    what kind of project you make to have Program.cs
    Besides I use Visual Studio 2010

  12. #12
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Problem with getting output in C#

    Go to File -> New -> Project...
    Make sure it says "Visual C#" under project types (on the left).
    Pick "Console Application" on the right.
    Type in a name and browse for location for the project to be created at.
    Click OK.
    It should create a new console app project, with the only file being Program.cs, and only one static method called Main. If you run it via Ctrl+F5, it will display an empty (usually black) console window, with the message "Press any key to continue . . .". If you run it with F5, the console window will briefly appear, but will immediately close.
    You should put your code inside the Main method, at least for now (if you're dealing with some basic Hello World code and such).

  13. #13
    Join Date
    Jun 2012
    Location
    Pennsylvania
    Posts
    10

    Re: Problem with getting output in C#

    Thanks a lot, it run now

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured