27/06/2024
π C # Basics: Variables and Data Types π
Hey CodeGurls! π©βπ» Ready to dive deeper into C #? Today, weβre going to explore the basics of variables and data types. Understanding these concepts is essential for building more complex programs.
π What are Variables?
Variables are like containers that hold data. Each variable has a specific type that determines what kind of data it can store.
Example Program:
Hereβs a simple program that uses different types of variables:
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
using System;
namespace VariableDemo
{
class Program
{
static void Main(string[] args)
{
int age = 25;
double height = 5.9;
char grade = 'A';
string name = "Lakshi";
bool isStudent = true;
Console.WriteLine("Name: " + name);
Console.WriteLine("Age: " + age);
Console.WriteLine("Height: " + height);
Console.WriteLine("Grade: " + grade);
Console.WriteLine("Is Student: " + isStudent);
}
}
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Breaking it Down:
>>>int age = 25; - Declares an integer variable named age and assigns it a value of 25.
>>>double height = 5.9; - Declares a double variable named height and assigns it a value of 5.9.
>>>char grade = 'A'; - Declares a char variable named grade and assigns it the character 'A'.
>>>string name = "Lakshi"; - Declares a string variable named name and assigns it the value "Lakshi".
>>>bool isStudent = true; - Declares a boolean variable named isStudent and assigns it the value true.
Your Turn!
Try creating a similar program with your own details and see the output. Share your progress and any questions in the comments below! π©
Keep coding and stay curious! π