THE .NET NAUNCE: BEYOND THE PROMPT, WHERE AI STOPS, EXPERIENCE BEGINS!

Your First Step in Programming (What You Should Learn First)

Start programming the right way by learning fundamentals like variables, loops, logic, and problem-solving for beginners.
first step into programming by dotnetverse

Note: The reference code in this article is written in C#.

Before deep diving into frameworks or languages, every beginner should understand the basics first. In this article, we will cover data types, variables, conditional statements, and loops using simple explanations and real-world thinking.

So, you got FIVE minutes? Let's clear up the AIR first and begin exploring programming fundamentals.

I would highly recommend, if you can just FIRE-UP a console Application in Visual Studio and practice alongside!

Data Types

Data types define what kind of value a variable can store. Some store numbers, some store text, while others store true or false values.

Basic Types

  • int — 32-bit integer
  • long — 64-bit integer
  • short — 16-bit integer
  • byte — 8-bit unsigned integer
  • sbyte — 8-bit signed integer
  • uint — unsigned 32-bit integer
  • ulong — unsigned 64-bit integer
  • ushort — unsigned 16-bit integer

Decimal & Logic Types

  • float — 32-bit decimal
  • double — 64-bit decimal
  • decimal — high precision decimal
  • bool — true or false
  • char — single character

Custom Value Types

  • struct — custom value type
  • enum — named constants

Reference Types

  • string — text values
  • object — base type of all objects
  • class — custom reference type
  • interface — contract definition
  • delegate — method reference
  • array — collection of same type
  • dynamic — resolved at runtime

Declaration & Assignment

Variables are used to store values in memory. Before using a variable, it must first be declared.

  • int x = 10; — variable declaration
  • string value = "DotNetVerse"; — a value/text
  • int a = 1, b = 2; — multiple assignments
  public static void Main()
{
    Console.WriteLine("Examples for the explained code @ DotNetVerse");
    int x = 10;
    string value = "DotNetVerse";
    int a = 1, b = 2; //Multiple Assignments
    Console.WriteLine(x);
    Console.WriteLine(value);
    Console.WriteLine("{0},{1}",a,b);
}
 Examples for the explained code @ DotNetVerse
10
DotNetVerse
1,2

“Now that we can store data, let’s make decisions using conditions.”

Conditional Statements

Conditional statements help programs make decisions based on conditions.

  • if — executes when condition is true
  • else if — checks another condition
  • else — executes when all conditions fail

We have three types of conditional statement checking:

First is equal to ( == ) Second is greater than ( > ) Third is smaller than ( < )

We can also combine checks: [ > / < with == ]

  if(x == 10)
{
    Console.WriteLine("x is 10");
}
else if(a>b)
{
    Console.WriteLine("a is greater than b");
}
else if (a<b)
{
    Console.WriteLine("a is smaller than b");
}
  
Examples for the explained code @ DotNetVerse
x is 10
a is smaller or equal to b
  

Loops

“Based on our condition, let’s print out without rewriting again and again using loops.”

Loops allow repetitive execution of code blocks without writing the same code multiple times.

  • for — classic counter-based loop
      public class Program
    {
        public static void Main()
        {
            Console.WriteLine("Examples for the explained code @ DotNetVerse");
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(i); // prints 0 to 4
            }
        }
    }
    
      Examples for the explained code @ DotNetVerse
    0
    1
    2
    3
    4
      
  • foreach — iterates through collections
    using System;
    
    public class Program
    {
        public static void Main()
        {
            Console.WriteLine("Examples for the explained code @ DotNetVerse");
            string[] names = { "Alice", "Bob", "Charlie" };
            foreach (string name in names)
            {
                Console.WriteLine(name);
            }
        }
    }
    
      Examples for the explained code @ DotNetVerse
    Alice
    Bob
    Charlie
      
  • while — checks condition before execution

    If count starts at 10, the body never runs — condition is checked first.

      public class Program
    {
        public static void Main()
        {
            Console.WriteLine("Examples for the explained code @ DotNetVerse");
            int count = 0;
            while (count < 5)
            {
                Console.WriteLine(count);
                count++;
            }
        }
    }
      Examples for the explained code @ DotNetVerse
    0
    1
    2
    3
    4
      
  • do while — executes once before checking condition

    Even though count < 5 is false from the start, it still prints 10 once — that's the key difference from while.

      public class Program
    {
        public static void Main()
        {
            Console.WriteLine("Examples for the explained code @ DotNetVerse");
            int count = 10;
            do
            {
                Console.WriteLine(count); // prints 10 - runs at least once
                count++;
            } while (count < 5);
        }
    }
      Examples for the explained code @ DotNetVerse
    10
    

Try above with your scenarios, imagine real-life scenarios and events to implement these once and for all, if you feel like something is out/missing please comment below, YOUR review is appreciated.

Post a Comment