Learn coding with amol
Hello my name is amol sharma or vineet and this is my seventh part of learn coding with amol and in this part we are learning C#.
Let's Start
PART-7 C#
π» Complete C# Guide
This guide covers all basics of the C# programming language with examples.
1. Hello World
The structure of a simple C# program.
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, World!");
}
}
2. Variables and Data Types
Variables store data. C# is strongly typed.
int age = 13;
double pi = 3.14;
char grade = 'A';
string name = "Amol";
3. Input and Output
Use Console.ReadLine() to get user input.
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.WriteLine("Hello, " + name);
4. if / else
Conditional execution in C#.
int x = 10;
if (x > 5) {
Console.WriteLine("Greater than 5");
} else {
Console.WriteLine("5 or less");
}
5. Loops
Use for and while loops to repeat actions.
for (int i = 0; i < 5; i++) {
Console.WriteLine(i);
}
int j = 0;
while (j < 5) {
Console.WriteLine(j);
j++;
}
6. Functions (Methods)
Reusable code blocks with parameters.
static void Greet(string name) {
Console.WriteLine("Hello, " + name);
}
static void Main() {
Greet("Amol");
}
7. Arrays
Store multiple values of the same type.
int[] numbers = {1, 2, 3};
Console.WriteLine(numbers[0]);
8. Classes and Objects
Core of object-oriented programming in C#.
class Person {
public string Name;
public int Age;
public void Greet() {
Console.WriteLine("Hello, I am " + Name);
}
}
class Program {
static void Main() {
Person p = new Person();
p.Name = "Amol";
p.Age = 13;
p.Greet();
}
}
9. File Handling
Read and write files using System.IO.
using System.IO;
File.WriteAllText("test.txt", "Hello file!");
string text = File.ReadAllText("test.txt");
Console.WriteLine(text);

Comments
Post a Comment