Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Console Application Pin
Jimmanuel13-May-09 8:10
Jimmanuel13-May-09 8:10 
GeneralRe: C# Console Application Pin
bigjoe11a13-May-09 8:17
bigjoe11a13-May-09 8:17 
GeneralRe: C# Console Application Pin
Jimmanuel13-May-09 8:38
Jimmanuel13-May-09 8:38 
GeneralRe: C# Console Application Pin
bigjoe11a13-May-09 10:00
bigjoe11a13-May-09 10:00 
GeneralRe: C# Console Application Pin
Jimmanuel13-May-09 11:33
Jimmanuel13-May-09 11:33 
GeneralRe: C# Console Application Pin
OriginalGriff13-May-09 8:43
mveOriginalGriff13-May-09 8:43 
GeneralRe: C# Console Application Pin
bigjoe11a13-May-09 10:26
bigjoe11a13-May-09 10:26 
GeneralRe: C# Console Application Pin
OriginalGriff13-May-09 22:24
mveOriginalGriff13-May-09 22:24 
Oooo! That is a simple one!
I can't teach you C# - I haven't got the time - but I'll do what I can.
Have you got any tools yet (C# compiler, etc)? If not, go to microsoft.com and search for "C# 2008 Express download" - this will give you a free copy of the C# IDE, with all the tools you need to do nearly everything with C#.
Do get a book on C# - there are some good ones out there, but I am not sure what you would need for starters. There is a free one available here C# Yellow book[^] which is used by the University of Hull for 1st year CS students and should cover the language basics.

Now, what have we got:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demo
    {
    class Program
        {
        static void Main(string[] args)
            {

...

            }
        }
    }

This is all overhead - it is automatically generated for you and provides a "framework" in which your program can run.

string name;
Console.Write("Enter your name: ");
name = Console.ReadLine();

All this does is declare a variable called "name" that can hold a string of text, prompt the user for his name, and read his response.
Console.WriteLine("\nWelcome :" + name);
Console.WriteLine("1) Game Menu");
Console.WriteLine("2) List Users");
Console.WriteLine("3) Help");
Console.WriteLine("9) Quit");
Console.Write("Choice : (1,2,3 or 9) ");

Print out the users selection of choices.
            int i = 0;
            do
                {

...


                }
            while (i != '9');

This sets up a loop - the program will go around and around here until the variable "i" contains the value '9', then it will exit the loop.
string s = Console.ReadLine();
if (s == "")
    {
    continue;
    }

Read the users menu selection into the variable "s", check that he didn't just press the ENTER key (if he did, ignore it and got back around the loop).
i = s[0];
switch (i)
    {
    case '1':
        Console.WriteLine("Game selected");
        // Handle game.
        break;
    case '2':
        Console.WriteLine("List selected");
        // List users
        break;
    case '3':
        Console.WriteLine("Help selected");
        // Help
        break;
    case '9':
        Console.WriteLine("Quit selected");
        break;
    default:
        Console.WriteLine("Invalid Key");
        break;
    }

Get the first character of the users input into the variable "i" (not a nice way, but it matched your code) and decide what to do with it. The "switch (i)" line says "look at the contents of the variable 'i', and compare it against the examples I will give you. If you find one which matches, then perform the instructions between the ':' character and the word 'break'"
'//' says "whatever text is to the right of me, ignore it, it is just a comment for poeple to read rather than an instruction for the computer".


Hope this helps a bit - it is really difficult to know where to start!

No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.

This message is made of fully recyclable Zeros and Ones

GeneralRe: C# Console Application Pin
bigjoe11a14-May-09 4:12
bigjoe11a14-May-09 4:12 
GeneralRe: C# Console Application Pin
OriginalGriff14-May-09 4:31
mveOriginalGriff14-May-09 4:31 
GeneralRe: C# Console Application Pin
bigjoe11a14-May-09 4:39
bigjoe11a14-May-09 4:39 
GeneralRe: C# Console Application Pin
OriginalGriff14-May-09 4:48
mveOriginalGriff14-May-09 4:48 
GeneralRe: C# Console Application Pin
bigjoe11a14-May-09 4:53
bigjoe11a14-May-09 4:53 
Questiondatagrid scroll Pin
michaelgr113-May-09 7:29
michaelgr113-May-09 7:29 
AnswerRe: datagrid scroll Pin
Dave Kreskowiak13-May-09 8:59
mveDave Kreskowiak13-May-09 8:59 
QuestionWindows resizing Pin
michaelgr113-May-09 7:06
michaelgr113-May-09 7:06 
AnswerRe: Windows resizing Pin
musefan13-May-09 7:10
musefan13-May-09 7:10 
AnswerRe: Windows resizing Pin
Giorgi Dalakishvili13-May-09 7:11
mentorGiorgi Dalakishvili13-May-09 7:11 
QuestionAppDomain Pin
humayunlalzad13-May-09 6:42
humayunlalzad13-May-09 6:42 
AnswerRe: AppDomain Pin
musefan13-May-09 6:58
musefan13-May-09 6:58 
GeneralRe: AppDomain Pin
Rajdeep.NET is BACK13-May-09 7:25
Rajdeep.NET is BACK13-May-09 7:25 
GeneralRe: AppDomain Pin
humayunlalzad13-May-09 7:26
humayunlalzad13-May-09 7:26 
GeneralRe: AppDomain Pin
Luc Pattyn13-May-09 7:32
sitebuilderLuc Pattyn13-May-09 7:32 
GeneralRe: AppDomain Pin
Kythen13-May-09 8:56
Kythen13-May-09 8:56 
AnswerRe: AppDomain Pin
Giorgi Dalakishvili13-May-09 7:33
mentorGiorgi Dalakishvili13-May-09 7:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.