[C#] Hello, C#

Discussion in 'Programming' started by -Hammad-, Dec 31, 2007.

?

Find this useful?

  1. Yep.

    50.0%
  2. Nope.

    50.0%
  1. #1
    C# (Pronounced CSharp) is a programming language following up from C++.
    I am going to teach you the Console Application most beginners use to get the hang of C#.
    Please note that this part of C# is the very beginning. It gets ALOT harder as you move up to more advanced projects.


    First, create a Console Application by following these steps:

    1. Open C# (Recommended: BETA 2008)

    Screenshot of main screen:

    [​IMG]

    1. File >> New Project or Ctrl + Shift + N

    File menu:
    [​IMG]
    1. Select Console Application from the Dialog Box

    Dialog Box:
    [​IMG]

    This should be the screen/code that Visual Studio generates for you:
    [​IMG]

    1. Edit the code generated, to this:


     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
       /// <summary>
        /// Summary for description for HelloCSharp class
        /// </summary>
        class HelloCSharp
        {
           /// <summary>
           /// The main entry point for the Console App.
            /// </summary>
           /// <param name="args"></param>
            static void Main(string[] args)
            {
                //
                //Say hello, C#
                Syestem.Console.WriteLine("Hello, C#");
                // All done.
            }
        }
    }
    
    Code (markup):
    On running, all this will display is "Hello, C#"​


    1. Edit that code, to this:


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        /// <summary>
        /// Summary for description for class Program
        /// </summary>
        class Program
        {
            /// <summary>
            /// The main entry point for the Console App.
            /// </summary>
            /// <param name="args"></param>
            static void Main(string[] args)
            {
                string inputString;
                
                //Get the users name.
                System.Console.WriteLine("Please tell me your name");
                inputString = System.Console.ReadLine();
    
                //Say hello.
                System.Console.WriteLine("Hello");
                System.Console.WriteLine(inputString);
                //All done
            }
        }
    }
    Code (markup):
    On running, this will ask for your name, then send a reply back.

    STUFF YOU NEED TO KNOW:

    • Namespaces define what is close by, and what is out of reach in the application. Every program must have a namespace.
    • In a C# program, the "using" keyword specifies which namespaces the program uses.
    • Every C# program must define an application class.
    • The entry point for a C# program is the "Main()" function. All C# Programs must have 1; no more no less, or they will build up errors.
    • The "WriteLine()" functions prints a line of text onto the screen followed by a line feed.
    • The "Write()" funtion prints text onto the screen, but without a line feed.
    • The "ReadLine()" funtion analyses test from the keyboard.
    • A "Line feed" is when some text is printed, then the cursor is moved onto the beginning of the next line.

    Please bear in mind that I have took the time to write this tutorial, and that is it written/made 100% by me.

    Happy coding!
    -Hammad-
     
    -Hammad-, Dec 31, 2007 IP
    blueparukia likes this.
  2. tokyoice

    tokyoice Well-Known Member

    Messages:
    3,327
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    165
    #2
    Welcome to DigitalPoint!

    Thank you for the tutorial!
     
    tokyoice, Dec 31, 2007 IP
  3. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #3
    Great tut....

    What I want to figure out is why nearly all C# tutorials I have read always start with Console Applications. I'd think starting with Windows Applications would be the best way to do it.....thats something to do when I have spare time.

    Anyway, nice tutorial, and I hope more people will start using C# - it is an amazing, powerful language.

    BP
     
    blueparukia, Dec 31, 2007 IP
  4. -Hammad-

    -Hammad- Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Console Applications are far easier to learn by and to code.
    Windows Applications have all that rubbish extra coding for the buttons, that just complicate the whole thing.

    Regards,
    -Hammad-
     
    -Hammad-, Dec 31, 2007 IP
  5. Arkserver

    Arkserver Banned

    Messages:
    2,533
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #5
    making Gui's in c# is easy, just drag and drop a component in the form builder. That said, cool tutorial.
     
    Arkserver, Dec 31, 2007 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have to agree with Hammad.

    You may be correct in that a tutorial can just say "drag this here and drop that there" but will it explain to me the code that is created to actually make the stuff work? Most likely not, exactly for the reason that Hammad gives.

    A tutorial that shows you what to drag and what to drop without explaining the generated code behind it is next to useless as far as I'm concerned...

    Hence, teach the basics of the language itself without the GUI code and from there the user can learn the drag and drop and because of the initial tutorials the user should be able to work out what the generated code does by themselves.
     
    TwistMyArm, Dec 31, 2007 IP
  7. Arkserver

    Arkserver Banned

    Messages:
    2,533
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #7
    true, i was making a similar post like you did but i got a timeout while posting and i didnt bother to write it again.
     
    Arkserver, Dec 31, 2007 IP