0% found this document useful (0 votes)
12 views2 pages

C# Exception Handling and Basics

The document covers various programming concepts in C#, including exception handling, for loops, constructors, file operations, and CRUD applications. It also briefly discusses EF Core data models and JavaScript topics like DOM manipulation and closures. Each concept is illustrated with sample code to demonstrate its functionality.

Uploaded by

sehranrubani007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

C# Exception Handling and Basics

The document covers various programming concepts in C#, including exception handling, for loops, constructors, file operations, and CRUD applications. It also briefly discusses EF Core data models and JavaScript topics like DOM manipulation and closures. Each concept is illustrated with sample code to demonstrate its functionality.

Uploaded by

sehranrubani007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Exception Handling in C#

Context / Idea: Exception handling is used to handle runtime errors using try, catch and finally
blocks.

Code:
try
{
int a = 10;
int b = 0;
[Link](a / b);
}
catch (Exception e)
{
[Link]("Error occurred");
}
finally
{
[Link]("Program ended");
}

For Loop in C#

Context / Idea: A for loop is used when the number of iterations is known beforehand.

Code:
for (int i = 1; i <= 5; i++)
{
[Link](i);
}

Default and Copy Constructor

Context / Idea: Default constructor initializes objects. Copy constructor copies one object into
another.

Code:
class Student
{
public int age;

public Student()
{
age = 18;
}

public Student(Student s)
{
age = [Link];
}
}

File Operations in C#

Context / Idea: File handling allows permanent data storage using [Link].

Code:
[Link]("[Link]", "Hello File");
string data = [Link]("[Link]");
[Link](data);
CRUD Application (Console)

Context / Idea: CRUD stands for Create, Read, Update and Delete operations.

Code:
List<string> users = new List<string>();
[Link]("Ali");
[Link]("Sara");
users[0] = "Ahmed";
[Link]("Sara");

EF Core Data Model

Context / Idea: EF Core maps C# classes to database tables.

Code:
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
}

JavaScript DOM Manipulation

Context / Idea: DOM manipulation allows dynamic changes to HTML using JavaScript.

Code:
[Link]("msg").innerHTML = "Changed!";

JavaScript Closure

Context / Idea: A closure allows a function to remember variables from its outer scope.

Code:
function counter() {
let count = 0;
return function () {
count++;
[Link](count);
}
}

You might also like