C# Lesson 1

Learn how to declare and use variables in the very first lesson from our series on learning C# for beginners.

The first lesson introduces 3 of the main c# variables. String, int, and double. Below you'll find the lesson video, notes, and the lesson's task.
Afterwards you can continue to the next lesson!
We also have the source code on GitHub.

using System;

namespace Lesson1
    class Variables
        static void Main(string[] args)

            string myString;
            myString = "This is a string value.";

            string mySecondString;
            mySecondString = "1000";

            int myInt;
            myInt = 1000;

            int mySecondInt = 2;

            Console.WriteLine("My second string: " + mySecondString);
            Console.WriteLine("My int: " + myInt);
            Console.WriteLine("My second int: " + mySecondInt);

            double myDouble = 3.14;
            Console.WriteLine("My Double: " + myDouble);



* In this program you will need to make the following variables with the given data types:
*   myName      -   Holds a string value
*   myAge       -   Holds an int value
*   someDecimal -   Holds a decimal value between 0 and 1 ex: .223
* Use string concatination and Console.WriteLine to print:
*   Hello, My name is 
*   I am 
*   A number between 0 and 1 is 
* Where the variable contents are displayed between the <>

// This lets us use Console.WriteLine in our program.
using System;

// We will learn about namespaces in a different lesson.
namespace Lesson1
    // We will learn about classes in a different lesson.
    class VariablesTask

        // For now, just know that this is the entry point to our program.
        // The code between the {} is the first section of code that will run.
        static void Main(string[] args)
            // This is a single line comment. It has no effect on the program.
            // It is used to write notes about what the code is doing.
            // ↓↓ Write a comment with your name and today's date under this line ↓↓

               This is a block comment.
               It can be used for multi lined comments.

               Make a NEW Block comment under this line 
               with your name and today's date on seperate lines

               ↓    ↓   ↓   ↓   ↓   ↓   ↓   ↓   ↓   ↓   ↓   ↓   ↓

            // I'll start out with an example.
            // This variable is named introText and holds a string data type.
            // Use the equalsign(=) to set the variable's value.  = Is called the assignment operator
            string introText = "Variables!"; //  <-- end lines of code with a ;
            Console.WriteLine("Today I'm going to learn " + introText);

            //Make a variable named myName with the string data type.
            //Set the variable equal to your name.
            //Display the text 'Hello, My name is '

            //Make a variable named myAge with the int data type.
            //Set the variable equal to your age.
            //Display the text 'I am '

            //Make a variable named someDecimal with the decimal data type.
            //Set the variable equal to a number between 0 and 1. ex: .223
            //Display the text 'A number btween 0 and 1 is '

        } // This curly brace ends Main 
    } // This curly brace ends VariablesTask
} // This curly brace ends Lesson1Task

Recommended posts

We have similar articles. Keep reading!

C# Lesson 9

Lesson 9 in our series about learning C# teaches you how to make Strings do your bidding.

C# Lesson 12

Lesson 12 in a our series about learning C# teaches you about working with methods.

C# Lesson 5

Run sections of your code only IF you want them to with the "if" statement in the 5th lesson from the series on learning C# for beginners.

C# Lesson 11

Lesson 11 in our series about learning C# teaches you about working with using boolean operators to control logic flow.


Log in or sign up to leave a comment.