C# introduction
C# introduction
C# introduction
---
---
What is C#?
It is used for building a wide range of applications, including web, desktop, mobile, games, and
enterprise software.
---
1. Object-Oriented:
Emphasizes using classes and objects for code structure.
2. Strongly Typed:
Every variable and object must have a specific data type, making the code safer and reducing errors.
3. Versatile:
Can be used for desktop applications (Windows Forms, WPF), web applications (ASP.NET), game
development (Unity), and more.
Automatically manages memory by removing objects that are no longer in use, reducing memory leaks.
---
Basic Syntax:
using System;
class Program
Console.WriteLine("Hello, World!");
Explanation:
---
3. Conditional Statements:
{
Console.WriteLine("You are an adult.");
else
Explanation:
The code checks if the value of age is greater than or equal to 18 and prints a message accordingly.
---
4. Loops:
Console.WriteLine(i);
}
Explanation: Loops from 1 to 5, printing each number.
---
1. Classes: Blueprint for creating objects (e.g., class Car { public string make; }).
4. Inheritance: Allows one class to inherit fields and methods from another.
5. Polymorphism: Enables methods to do different things based on the object it is acting on.
---
---
Summary:
C# is a powerful, versatile, and easy-to-learn language for developing a wide range of applications.
It supports modern programming concepts like OOP and memory management, making it ideal for both
beginners and experienced developers.
---
This slide provides an introduction to the basics of C# coding, covering the language’s core features,
syntax, and key applications.
In C#, instead of using cin (which is used in C++), we use the Console.ReadLine() method to input a
string, such as a name, from the user. Here's an example of how to prompt the user for their name and
display it back.
using System;
class Program
}
Explanation:
Console.WriteLine("Please enter your name:");: Outputs the prompt asking the user to enter their name.
Console.ReadLine();: Reads the input from the user and stores it in the name variable.
Console.WriteLine("Hello, " + name + "!");: Displays a message with the entered name.
How it Works:
When you run this code, the console will prompt the user to enter their name. After entering the name
and pressing Enter, it will greet the user by their name.
Example output:
Aneeza