Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views9 pages

C# introduction

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 9

Slide: Basic Information about C# Coding

---

Title: Introduction to C# Programming

---

What is C#?

C# (pronounced "C-sharp") is a modern, object-oriented programming language developed by Microsoft


in 2000 as part of the .NET framework.

It is used for building a wide range of applications, including web, desktop, mobile, games, and
enterprise software.

---

Key Features of C#:

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.

4. Automatic Garbage Collection:

Automatically manages memory by removing objects that are no longer in use, reducing memory leaks.

---
Basic Syntax:

1. Hello World Example:

using System;

class Program

static void Main(string[] args)

Console.WriteLine("Hello, World!");

Explanation:

using System;: Imports the System namespace.

class Program: Defines a class named Program.

static void Main(string[] args): The entry point of a C# application.

Console.WriteLine(): Outputs the string "Hello, World!" to the console.


---

2. Variables and Data Types:

int: Stores whole numbers (e.g., int age = 25;).

double: Stores decimal numbers (e.g., double price = 9.99;).

string: Stores text (e.g., string name = "John";).

bool: Stores true/false values (e.g., bool isStudent = true;).

---

3. Conditional Statements:

int age = 18;

if (age >= 18)

{
Console.WriteLine("You are an adult.");

else

Console.WriteLine("You are a minor.");

Explanation:

The code checks if the value of age is greater than or equal to 18 and prints a message accordingly.

---

4. Loops:

For Loop Example:

for (int i = 1; i <= 5; i++)

Console.WriteLine(i);

}
Explanation: Loops from 1 to 5, printing each number.

---

Object-Oriented Programming (OOP) in C#:

1. Classes: Blueprint for creating objects (e.g., class Car { public string make; }).

2. Objects: Instances of classes (e.g., Car myCar = new Car();).

3. Encapsulation: Restricts direct access to some components of an object.

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.
---

Popular Applications of C#:

Windows Desktop Applications: Using Windows Forms or WPF.

Web Applications: Using ASP.NET framework.

Game Development: Using the Unity game engine.

Cloud Computing: With Microsoft Azure and .NET Core.

---

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.

Example: Inputting and Displaying Your Name in C#

using System;

class Program

static void Main(string[] args)

// Prompt the user to enter their name

Console.WriteLine("Please enter your name:");

// Read the user's input (name) from the console

string name = Console.ReadLine();

// Display the user's name

Console.WriteLine("Hello, " + name + "! Welcome to C# programming.");

}
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:

Please enter your name:

Aneeza

Hello, Aneeza! Welcome to C# programming.

You might also like