________________________________________ C# Day 1 Class, Method, Object DAY 1: 1. C# Introduction 2. Class, Method, Object 3. Same namespace and Different namespace 4. Encapsulation QUESTIONS (Theory): 1. What is platform independent in C#? 2. What is open-source in C#? 3. Difference between .NET Framework, .NET Core, and .NET 5/6? 4. Why choose C# for development? 5. What is the latest version of C# and which version are you using in your project? 6. What is the latest version of Visual Studio, and which version are you using in your project? 7. Difference between C++ and C#? 8. Features of C#? 9. What type of tool do you use in your project to execute C# code? 10. Difference between class, method, and object in C#? 11. Where do objects store in C#? 12. How to access a method of a class in a different namespace? 13. What is encapsulation in C#? 14. Coding standards to create project, class, method, namespace, and object in C#? 15. What gives C# its "write once, run anywhere" nature? QUESTIONS (Programs): QUESTION 1: Project: EmployeeDetails Namespace: Org.Emp Class: Employee Methods: EmpId(), EmpName(), EmpDob(), EmpPhone(), EmpEmail(), EmpAddress() Description: Create an object for the Employee class and call the above methods, following all coding standards. ________________________________________ QUESTION 2: Project: GreensAddress Namespace: Org.Add Class: GreensTech Methods: GreensOmr(), GreensAdayar(), GreensTambaram(), GreensVelacherry(), GreensAnnaNagar() Description: Create an object for the GreensTech class and call the above methods, following all coding standards. ________________________________________ QUESTION 3: Project: CompanyDetails Namespace: Org.Company Class: CompanyInfo Methods: CompanyName(), CompanyId(), CompanyAddress() Description: Create an object for the CompanyInfo class and call the above methods, following all coding standards. ________________________________________ QUESTION 4: Project: MyPhone Namespace: Org.Phone Class: PhoneInfo Methods: PhoneName(), PhoneMieiNum(), Camera(), Storage(), OsName() Description: Create an object for the PhoneInfo class and call the above methods, following all coding standards. ________________________________________ QUESTION 5: Project: LanguageDetails Namespace: Org.Lang Class: LanguageInfo Methods: TamilLanguage(), EnglishLanguage(), HindiLanguage() Class: StateDetails Methods: SouthIndia(), NorthIndia() Description: Create an object for LanguageInfo and StateDetails inside the StateDetails class and call both class methods, following all coding standards. ________________________________________ QUESTION 6: Project: EmployeeInformation Namespace: Org.Emp Class: Employee Methods: EmpName() Namespace: Org.Company Class: Company Methods: CompanyName() Namespace: Org.Client Class: Client Methods: ClientName() Namespace: Org.Project Class: Project Methods: ProjectName() Description: Create an object for all four classes inside the Employee class and call all class methods, following all coding standards. ________________________________________ QUESTION 7: Project: PhoneDetails Namespace: Org.Phone Class: ExternalStorage Methods: Size() Class: InternalStorage Methods: ProcessorName(), RamSize() Description: Create an object for ExternalStorage and InternalStorage inside the InternalStorage class and call both class methods, following all coding standards. ________________________________________ QUESTION 8: Project: CollegeInformation Namespace: Org.College Class: College Methods: CollegeName(), CollegeCode(), CollegeRank() Class: Student Methods: StudentName(), StudentDept(), StudentId() Class: Hostel Methods: HostelName() Class: Dept Methods: DeptName() Description: Create an object for all four classes inside the College class and call all class methods, following all coding standards. ________________________________________ QUESTION 9: Project: VehicleInformation Namespace: Org.AllVehicle Class: Vehicle Methods: VehicleNecessery() Namespace: Org.TwoWheeler Class: TwoWheeler Methods: Bike(), Cycle() Namespace: Org.ThreeWheeler Class: ThreeWheeler Methods: Auto() Namespace: Org.FourWheeler Class: FourWheeler Methods: Car(), Bus(), Lorry() Description: Create an object for all four classes inside the Vehicle class and call all class methods, following all coding standards. ________________________________________ QUESTION 10: Project: TransportInformation Namespace: Org.Transport Class: Transport Methods: TransportForm() Namespace: Org.Road Class: Road Methods: Bike(), Cycle(), Bus(), Car() Namespace: Org.Air Class: Air Methods: AeroPlane(), Helicopter() Namespace: Org.Water Class: Water Methods: Boat(), Ship() Description: Create an object for all four classes inside the Transport class and call all class methods, following all coding standards. ________________________________________ QUESTION 11: Project: NetworkInformation Namespace: Org.Network Class: Wifi Methods: WifiName() Class: MobileData Methods: DataName() Class: Lan Methods: LanName() Class: Wireless Methods: ModemName() Description: Create an object for all four classes inside the Wifi class and call all class methods, following all coding standards. ________________________________________________________________________________ C# Day 2: Inheritance, Scanner, Data Types, Access Specifiers DAY 2: 1. Inheritance 2. Access Specifiers 3. Data Types 4. Scanner class (equivalent in C#: Console.ReadLine()) QUESTIONS (Theory): 1. What is meant by inheritance in C#? 2. Types of inheritance and explain all types in C#? 3. What is meant by multiple inheritance in C#? Why doesn't C# support multiple inheritance directly? 4. Difference between hybrid and hierarchical inheritance in C#? 5. What is the use of access specifiers and types in C#? 6. Difference between public and protected in C#? 7. What is meant by a Wrapper class in C#? 8. What is the default value of string in C#? 9. What is the difference between primitive and non-primitive data types in C#? 10. What is the default namespace in C#? 11. What is the base class of all C# classes? 12. What is the use of the Scanner class in Java and its equivalent in C#? 13. What are the different methods available in the Scanner class? (For C#, mention methods of Console or TextReader) 14. The Scanner class in Java is under which package? (For C#, mention relevant namespaces) 15. Difference between next() and nextLine() methods in Scanner class and their equivalents in C#. QUESTIONS (Programs): QUESTION 1: Description: Using C# Console.ReadLine(), get the following details: • EmpId • EmpName • EmpEmail • EmpPhoneNo • EmpSalary • EmpGender • EmpCity using System; class EmployeeDetails { static void Main() { Console.Write("Enter EmpId: "); string empId = Console.ReadLine(); Console.Write("Enter EmpName: "); string empName = Console.ReadLine(); Console.Write("Enter EmpEmail: "); string empEmail = Console.ReadLine(); Console.Write("Enter EmpPhoneNo: "); string empPhoneNo = Console.ReadLine(); Console.Write("Enter EmpSalary: "); decimal empSalary = Convert.ToDecimal(Console.ReadLine()); Console.Write("Enter EmpGender: "); string empGender = Console.ReadLine(); Console.Write("Enter EmpCity: "); string empCity = Console.ReadLine(); Console.WriteLine($"\nEmployee Details: {empName}, {empEmail}, {empPhoneNo}, {empSalary}, {empGender}, {empCity}"); } } ________________________________________ QUESTION 2: Description: Using C# Console.ReadLine(), get the following details for a student: • StudentId • StudentName • Marks (Mark1 to Mark5) Then, find the total and average marks. using System; class StudentDetails { static void Main() { Console.Write("Enter StudentId: "); string studentId = Console.ReadLine(); Console.Write("Enter StudentName: "); string studentName = Console.ReadLine(); Console.Write("Enter Marks for Mark1: "); int mark1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Marks for Mark2: "); int mark2 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Marks for Mark3: "); int mark3 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Marks for Mark4: "); int mark4 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Marks for Mark5: "); int mark5 = Convert.ToInt32(Console.ReadLine()); int total = mark1 + mark2 + mark3 + mark4 + mark5; double average = total / 5.0; Console.WriteLine($"Total Marks: {total}, Average: {average}"); } } ________________________________________ QUESTION 3: Project Name: LanguageDetails Namespace and Classes: • org.all: LanguageClass • org.tamil: Tamil • org.english: English • org.telgu: Telgu Description: Use multilevel inheritance to call methods from different classes in a hierarchy. namespace org.all { class LanguageClass { public void AllLanguage() { Console.WriteLine("All Languages: Tamil, English, Telugu"); } } } namespace org.tamil { class Tamil : org.all.LanguageClass { public void TamilLanguage() { Console.WriteLine("Tamil Language"); } } } namespace org.english { class English : org.all.LanguageClass { public void EnglishLanguage() { Console.WriteLine("English Language"); } } } namespace org.telgu { class Telugu : org.all.LanguageClass { public void TeluguLanguage() { Console.WriteLine("Telugu Language"); } } } class Program { static void Main() { Tamil tamil = new Tamil(); tamil.AllLanguage(); tamil.TamilLanguage(); English english = new English(); english.AllLanguage(); english.EnglishLanguage(); Telugu telugu = new Telugu(); telugu.AllLanguage(); telugu.TeluguLanguage(); } } ________________________________________ QUESTION 4: Description: Use multilevel inheritance for the SouthIndia project with the following classes: • org.india: India • org.tamilnadu: Tamilnadu • org.kerala: Kerala • org.andrapradesh: AndhraPradesh namespace org.india { class India { public void IndiaMethod() { Console.WriteLine("India"); } } } namespace org.tamilnadu { class Tamilnadu : org.india.India { public void TamilLanguage() { Console.WriteLine("Tamil Language"); } } } namespace org.kerala { class Kerala : org.india.India { public void Malayalam() { Console.WriteLine("Malayalam Language"); } } } namespace org.andrapradesh { class AndhraPradesh : org.india.India { public void Telugu() { Console.WriteLine("Telugu Language"); } } } class Program { static void Main() { Tamilnadu tamilnadu = new Tamilnadu(); tamilnadu.IndiaMethod(); tamilnadu.TamilLanguage(); Kerala kerala = new Kerala(); kerala.IndiaMethod(); kerala.Malayalam(); AndhraPradesh andhra = new AndhraPradesh(); andhra.IndiaMethod(); andhra.Telugu(); } } ________________________________________ QUESTION 5: Project Name: CollegeInformation Classes: • College: CollegeName(), CollegeCode(), CollegeRank() • Student: StudentName(), StudentDept(), StudentId() • Hostel: HostelName() • Dept: DeptName() Description: Create a multilevel inheritance structure where the Student class calls methods from all the other classes. namespace org.college { class College { public void CollegeName() { Console.WriteLine("College Name: XYZ College"); } public void CollegeCode() { Console.WriteLine("College Code: 1234"); } public void CollegeRank() { Console.WriteLine("College Rank: 1"); } } class Student : College { public void StudentName() { Console.WriteLine("Student Name: John"); } public void StudentDept() { Console.WriteLine("Department: Computer Science"); } public void StudentId() { Console.WriteLine("Student ID: 56789"); } } } class Program { static void Main() { Student student = new Student(); student.CollegeName(); student.CollegeCode(); student.CollegeRank(); student.StudentName(); student.StudentDept(); student.StudentId(); } } ________________________________________ DAY 3- C# - THEORY QUESTIONS 1. What is meant by polymorphism? o Polymorphism in C# refers to the ability of a method or object to behave differently based on the context. There are two types:  Compile-time polymorphism (Method Overloading): Achieved by defining multiple methods with the same name but different signatures.  Run-time polymorphism (Method Overriding): Achieved when a derived class provides its own implementation of a method defined in a base class using the override keyword. 2. Difference between method overloading and method overriding? o Method Overloading: Occurs when multiple methods with the same name but different parameters are defined within the same class. o Method Overriding: Occurs when a derived class provides a new implementation of a method inherited from the base class using the override keyword. Example: csharp Copy code class Example { // Method Overloading public void Print(int num) { Console.WriteLine(num); } public void Print(string text) { Console.WriteLine(text); } } class BaseClass { public virtual void Display() { Console.WriteLine("Base display"); } } class DerivedClass : BaseClass { public override void Display() { Console.WriteLine("Derived display"); } // Method Overriding } 3. What is meant by Abstraction? o Abstraction in C# refers to hiding the implementation details and exposing only the necessary functionalities to the user. This can be achieved through abstract classes and interfaces. 4. Difference between Abstract class and Interface? o Abstract Class: Can have both abstract (without implementation) and concrete (with implementation) methods. It can contain fields, properties, and constructors. o Interface: Contains only method signatures (without implementation) and can be implemented by classes or structs. Example: csharp Copy code // Abstract Class abstract class Animal { public abstract void Sound(); } // Interface interface IAnimal { void Sound(); } 5. What is meant by abstract method? o An abstract method is a method that is declared in an abstract class or interface but does not have an implementation. Derived classes must provide the implementation for this method. 6. Can we create an object for an abstract class? o No, abstract classes cannot be instantiated directly. They are meant to be inherited by other classes that provide implementations for the abstract methods. 7. In an interface, can we make a method static? o No, methods in an interface cannot be static. They must be implemented by the classes that implement the interface. 8. In an interface, can we make a method final? o No, methods in an interface cannot be final. Interfaces are meant to provide method declarations that must be implemented by the classes that implement the interface. 9. How will we achieve multiple inheritance in C#, and write code for that? o Multiple inheritance is supported in C# through interfaces. A class can implement multiple interfaces. Example: csharp Copy code interface IFirst { void Method1(); } interface ISecond { void Method2(); } class MultipleInheritance : IFirst, ISecond { public void Method1() { Console.WriteLine("Method1 from IFirst"); } public void Method2() { Console.WriteLine("Method2 from ISecond"); } } ________________________________________ C# - PROGRAMMING QUESTIONS QUESTION 1: Find the answer for below questions and tell whether it is possible or not? In C#, interfaces can only be implemented by classes, and a class can inherit from another class or implement multiple interfaces. Here's the breakdown of the scenarios: 1. I implements I: Not possible because an interface cannot implement itself. 2. I implements C: Not possible because an interface cannot implement a class. 3. I implements A: Not possible because an abstract class cannot be implemented by an interface. 4. I extends I: Not possible because an interface cannot extend another interface. 5. I extends C: Not possible because an interface cannot extend a class. 6. I extends A: Not possible because an interface cannot extend an abstract class. Similarly, the rest of the combinations such as C implements I, C implements A, A implements I, etc., are not allowed for the same reasons. QUESTION 2: Overload the empId() method based on different data types in arguments. csharp Copy code namespace org.emp { public class Employee { public void empId(int id) { Console.WriteLine("Employee ID (int): " + id); } public void empId(string id) { Console.WriteLine("Employee ID (string): " + id); } public void empId(double id) { Console.WriteLine("Employee ID (double): " + id); } } class Program { static void Main(string[] args) { Employee emp = new Employee(); emp.empId(101); // Int emp.empId("E102"); // String emp.empId(103.5); // Double } } } QUESTION 3: Overload the companyName() method based on different numbers of arguments. csharp Copy code namespace org.company { public class CompanyInfo { public void companyName(string name) { Console.WriteLine("Company Name: " + name); } public void companyName(string name, string location) { Console.WriteLine($"Company: {name}, Location: {location}"); } public void companyName(string name, string location, int year) { Console.WriteLine($"Company: {name}, Location: {location}, Year Established: {year}"); } } class Program { static void Main(string[] args) { CompanyInfo company = new CompanyInfo(); company.companyName("TechCorp"); company.companyName("TechCorp", "New York"); company.companyName("TechCorp", "New York", 1999); } } } QUESTION 4: Overload the phoneInfo() method based on different datatype order in arguments. csharp Copy code namespace org.phone { public class Phone { public void phoneInfo(string brand, double price) { Console.WriteLine($"Brand: {brand}, Price: {price}"); } public void phoneInfo(double price, string brand) { Console.WriteLine($"Price: {price}, Brand: {brand}"); } } class Program { static void Main(string[] args) { Phone phone = new Phone(); phone.phoneInfo("Apple", 999.99); // Brand, Price phone.phoneInfo(999.99, "Apple"); // Price, Brand } } } QUESTION 5: Overload the greensOmr() method based on order, type, and number. csharp Copy code namespace org.add { public class GreensTech { public void greensOmr(string location) { Console.WriteLine($"Location: {location}"); } public void greensOmr(int number) { Console.WriteLine($"Number: {number}"); } public void greensOmr(string location, int number) { Console.WriteLine($"Location: {location}, Number: {number}"); } } class Program { static void Main(string[] args) { GreensTech greensTech = new GreensTech(); greensTech.greensOmr("OMR"); greensTech.greensOmr(15); greensTech.greensOmr("OMR", 15); } } } QUESTION 6: Override the deposit() method in AxisBank. csharp Copy code namespace org.bank { public class BankInfo { public virtual void deposit() { Console.WriteLine("Bank Deposit Method"); } } public class AxisBank : BankInfo { public override void deposit() { Console.WriteLine("Axis Bank Deposit Method"); } } class Program { static void Main(string[] args) { AxisBank axisBank = new AxisBank(); axisBank.deposit(); } } } QUESTION 7: Override the ug() and pg() methods in Arts. csharp Copy code namespace org.edu { public class Education { public virtual void ug() { Console.WriteLine("Undergraduate course"); } public virtual void pg() { Console.WriteLine("Postgraduate course"); } } public class Arts : Education { public override void ug() { Console.WriteLine("UG in Arts"); } public override void pg() { Console.WriteLine("PG in Arts"); } } class Program { static void Main(string[] args) { Arts arts = new Arts(); arts.ug(); arts.pg(); } } } QUESTION 8: Override the ug() and pg() methods in College. csharp Copy code namespace org.univ { public class University { public virtual void ug() { Console.WriteLine("University UG Course"); } public virtual void pg() { Console.WriteLine("University PG Course"); } } public class College : University { public override void ug() { Console.WriteLine("College UG Course"); } public override void pg() { Console.WriteLine("College PG Course"); } } class Program { static void Main(string[] args) { College college = new College(); college.ug(); college.pg(); } } } QUESTION 9: Override the cost() and speed() methods in Ktm. csharp Copy code namespace org.bike { public interface Bike { void cost(); void speed(); } public class Ktm : Bike { public void cost() { Console.WriteLine("KTM Bike Cost: $12000"); } public void speed() { Console.WriteLine("KTM Speed: 180 km/h"); } } class Program { static void Main(string[] args) { Ktm ktm = new Ktm(); ktm.cost(); ktm.speed(); } } } QUESTION 10: Achieve multiple inheritance by using interfaces. csharp Copy code namespace org.computer { public interface HardWare { void hardwareResources(); } public interface Software { void softwareResources(); } public class Desktop : HardWare, Software { public void hardwareResources() { Console.WriteLine("Desktop Hardware Resources"); } public void softwareResources() { Console.WriteLine("Desktop Software Resources"); } } class Program { static void Main(string[] args) { Desktop desktop = new Desktop(); desktop.hardwareResources(); desktop.softwareResources(); } } } Day 4: Control Statements ________________________________________ Theory Questions 1. What is the difference between break and continue? o break: Terminates the entire loop or switch statement. The control is transferred to the first statement after the loop or switch. o continue: Skips the current iteration of the loop and moves to the next iteration. The rest of the code in the current iteration is ignored. 2. Can we use continue statement in a switch? o No, the continue statement cannot be used inside a switch block directly, as it is designed to be used inside loops (for, while, do-while) to skip the current iteration. 3. What is meant by control statements and types? o Control statements are used to control the flow of execution in a program. The types of control statements are:  Conditional statements: if, else, else if, switch  Looping statements: for, while, do-while  Jump statements: break, continue, return 4. What is meant by a for loop? o A for loop is used for executing a block of code a fixed number of times. It consists of an initialization, a condition, and an increment/decrement operation. Syntax: csharp Copy code for (initialization; condition; increment/decrement) { // code to be executed } 5. Can you explain the execution process of a for loop? o The for loop follows these steps: 1. The initialization part is executed once at the beginning. 2. The condition is evaluated. If true, the loop body is executed. 3. After each iteration, the increment/decrement is applied, and the condition is checked again. 4. The loop ends when the condition becomes false. 6. What is the difference between while and do-while loops? o while loop: The condition is checked before the loop body is executed. If the condition is false initially, the loop body is not executed. o do-while loop: The condition is checked after the loop body is executed. This ensures that the loop body is always executed at least once, even if the condition is false. 7. What is the use of the default keyword in a switch statement? o The default keyword is used in a switch statement to specify the block of code that will execute if none of the case conditions are met. 8. Difference between for and while loop? o for loop: Typically used when the number of iterations is known beforehand. o while loop: Used when the number of iterations is not known, and the loop continues until a specific condition is met. ________________________________________ Find the Output Questions QUESTION 1: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { for (int i = 1; i <= 100; i++) { if (i == 5) { // No action, no break or continue } Console.WriteLine(i); } } } } Output: 1, 2, 3, 4, 5, 6, 7, ..., 100 (No change as if(i==5) does nothing) ________________________________________ QUESTION 2: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { for (int i = 1; i <= 10; i++) { if (i == 5) { break; } Console.WriteLine(i); } } } } Output: 1, 2, 3, 4 (Loop stops when i == 5) ________________________________________ QUESTION 3: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { for (int i = 1; i <= 10; i++) { if (i == 5) { continue; } Console.WriteLine(i); } } } } Output: 1, 2, 3, 4, 6, 7, 8, 9, 10 (Skips 5) ________________________________________ QUESTION 4: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { Console.WriteLine(j); } } } } } Output: 1, 2, 3 1, 2, 3 1, 2, 3 ________________________________________ QUESTION 5: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { Console.WriteLine(i); } } } } } Output: 1, 1, 1 2, 2, 2 3, 3, 3 ________________________________________ QUESTION 6: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { for (int i = 1; i <= 3; i++) { for (int j = 1; j <= i; j++) { Console.WriteLine(j); } } } } } Output: 1 1, 2 1, 2, 3 ________________________________________ QUESTION 7: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { for (int i = 1; i <= 3; i++) { for (int j = i + 1; j <= 3; j++) { Console.WriteLine(j); } } } } } Output: 2 3 2 3 3 ________________________________________ QUESTION 8: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { for (int i = 1; i <= 3; i++) { for (int j = i + 1; j <= i; j++) { Console.WriteLine(j); } } } } } Output: No output (Condition j <= i is never true) ________________________________________ QUESTION 9: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { int i = 5; if (i == 5) { break; // Break cannot be used here, it's not inside a loop } Console.WriteLine(i); } } } Output: Compilation error: break cannot be used outside of a loop. ________________________________________ QUESTION 10: csharp Copy code using System; namespace TestApp { class Program { static void Main(string[] args) { int i = 5; if (i == 5) { continue; // Continue cannot be used here, it's not inside a loop } Console.WriteLine(i); } } } Output: Compilation error: continue cannot be used outside of a loop. ________________________________________ Programming Questions QUESTION 1: csharp Copy code using System; namespace VotingEligibility { class Program { static void Main(string[] args) { Console.WriteLine("Enter your age: "); int age = Convert.ToInt32(Console.ReadLine()); if (age >= 18) { Console.WriteLine("Eligible to vote."); } else { Console.WriteLine("Not eligible to vote."); } } } } QUESTION 2: csharp Copy code using System; namespace EvenOddCheck { class Program { static void Main(string[] args) { Console.WriteLine("Enter a number: "); int num = Convert.ToInt32(Console.ReadLine()); if (num % 2 == 0) { Console.WriteLine("Even"); } else { Console.WriteLine("Odd"); } } } } QUESTION 3: csharp Copy code using System; namespace EvenNumbers { class Program { static void Main(string[] args) { for (int i = 2; i <= 100; i += 2) { Console.Write(i + " "); } } } } QUESTION 4: csharp Copy code using System; namespace SumOfOddNumbers { class Program { static void Main(string[] args) { int sum = 0; for (int i = 1; i <= 100; i += 2) { sum += i; } Console.WriteLine("Sum of odd numbers between 1 and 100: " + sum); } } } QUESTION 5: csharp Copy code using System; namespace CountEvenNumbers { class Program { static void Main(string[] args) { int count = 0; for (int i = 2; i <= 100; i += 2) { count++; } Console.WriteLine("Count of even numbers between 1 and 100: " + count); } } } QUESTION 6: csharp Copy code using System; namespace Factorial { class Program { static void Main(string[] args) { Console.WriteLine("Enter a number: "); int num = Convert.ToInt32(Console.ReadLine()); int factorial = 1; for (int i = 1; i <= num; i++) { factorial *= i; } Console.WriteLine("Factorial of " + num + " is: " + factorial); } } } QUESTION 7: csharp Copy code using System; namespace FibonacciSeries { class Program { static void Main(string[] args) { int a = 0, b = 1, next; Console.Write("Fibonacci Series: "); for (int i = 0; i < 10; i++) { next = a + b; Console.Write(next + " "); a = b; b = next; } } } } QUESTION 8: csharp Copy code using System; namespace PrimeNumberCheck { class Program { static void Main(string[] args) { Console.WriteLine("Enter a number: "); int num = Convert.ToInt32(Console.ReadLine()); bool isPrime = true; for (int i = 2; i <= num / 2; i++) { if (num % i == 0) { isPrime = false; break; } } Console.WriteLine(isPrime ? "Prime number" : "Not a prime number"); } } } QUESTION 9: csharp Copy code using System; namespace NumberPatterns { class Program { static void Main(string[] args) { // Pattern 1 for (int i = 1; i <= 7; i++) { for (int j = 1; j <= i; j++) { Console.Write(j + " "); } Console.WriteLine(); } } } } Day 5: Constructors, this and super, Types of Variables, Static/Final ________________________________________ Theory Questions 1. What is meant by a constructor and its types? o A constructor is a special method in a class used to initialize objects. It is automatically called when an instance of the class is created. Constructors do not have a return type. o Types of constructors:  Default constructor: A constructor that takes no arguments.  Parameterized constructor: A constructor that takes arguments to initialize an object with specific values. 2. Explain the types of variables. o Local variable: Defined inside a method or a block. It is only accessible within that method or block. o Instance variable: Defined inside a class but outside any method. It is associated with instances of the class. o Class/Static variable: Defined with the static keyword. It is shared among all instances of the class. 3. Do constructors have any return type? o No, constructors do not have a return type, not even void. Their purpose is to initialize the object. 4. Syntax for creating a constructor? o The syntax for creating a constructor is: csharp Copy code public ClassName() { // Initialization code } 5. What are the rules for defining a constructor? o The constructor must have the same name as the class. o Constructors do not have a return type. o It can be default or parameterized. o It is called automatically when an object is created. 6. Why is a return type not allowed for constructors? o A constructor is not intended to return a value; its purpose is to initialize the object. Allowing a return type would conflict with its purpose. 7. Can we declare a constructor as 'private'? o Yes, a constructor can be declared private, typically used in singleton design patterns to restrict the creation of instances outside the class. 8. Why is the compiler-given constructor called the default constructor? o The default constructor is the constructor provided by the compiler if no constructor is explicitly defined in the class. It initializes the object with default values. 9. What is constructor chaining and how can it be achieved in Java? o Constructor chaining refers to the process where one constructor calls another constructor in the same class or superclass. It is achieved using this() for the current class and super() for the parent class. 10. Can we use this() and super() in a method? o No, this() and super() can only be used in constructors, not in regular methods. 11. What are the common uses of the this keyword in Java? o Referring to the current class instance. o Accessing instance variables and methods. o Calling another constructor in the same class (this()). 12. Types of variables? o Local variables, Instance variables, Static variables. 13. What is meant by local variable, instance variable, and class/static variable? o Local variable: Defined within methods or blocks and is accessible only within that scope. o Instance variable: Associated with an object instance and defined within a class but outside methods. o Static variable: Belongs to the class rather than instances of the class. It is shared across all instances. 14. What is the meaning of the static keyword in Java? o The static keyword is used to declare class-level fields and methods. It means that the field or method is shared by all instances of the class. 15. Can we override a static method in Java? o No, static methods cannot be overridden. However, they can be hidden by redefining them in the subclass. 16. Can we overload a static method in Java? o Yes, static methods can be overloaded, meaning we can define multiple static methods with the same name but different parameter lists. 17. What is meant by static variable? o A static variable is a class-level variable that is shared across all instances of the class. 18. What is meant by static method? o A static method is a method that belongs to the class rather than an instance and can be called without creating an object of the class. 19. What is meant by the final keyword and what happens when we declare final for a class, method, or variable? o final:  Final class: Cannot be subclassed.  Final method: Cannot be overridden by subclasses.  Final variable: Its value cannot be changed once assigned. 20. What is the difference between final and finalize keyword? o final: Used to define constants, prevent inheritance, or prevent method overriding. o finalize: A method used for garbage collection, called before an object is destroyed. 21. Where do local, static, and class variables store in JVM? o Local variables: Stored on the stack. o Static variables: Stored in the method area of the JVM. o Instance variables: Stored in the heap. ________________________________________ Find the Output Questions (converted to C#) QUESTION 1: csharp Copy code using System; public class A { public A() : this("JAVA") { Console.WriteLine("Default constructor..."); } public A(int id) : this(3456.5678f) { Console.WriteLine(id); } public A(string name) : this(12) { Console.WriteLine(name); } public A(float sal) { Console.WriteLine(sal); } public static void Main(string[] args) { A a = new A(); } } Output: kotlin Copy code 12 JAVA 3456.5678 Default constructor... ________________________________________ QUESTION 2: csharp Copy code using System; public class B { public B() { Console.WriteLine("Super class"); } } public class A : B { public A() { Console.WriteLine("Default constructor..."); } public static void Main(string[] args) { A a = new A(); } } Output: kotlin Copy code Super class Default constructor... ________________________________________ QUESTION 3: csharp Copy code using System; public class B { public B() { Console.WriteLine("Super class"); } public B(int id) { Console.WriteLine(id); } } public class A : B { public A() { Console.WriteLine("Default constructor..."); } public static void Main(string[] args) { A a = new A(); } } Output: kotlin Copy code Super class Default constructor... ________________________________________ QUESTION 4: csharp Copy code using System; public class B { public B() { Console.WriteLine("Super class"); } public B(int id) { Console.WriteLine(id); } } public class A : B { public A() : base(12) { Console.WriteLine("Default constructor..."); } public static void Main(string[] args) { A a = new A(); } } Output: kotlin Copy code 12 Default constructor... ________________________________________ QUESTION 5: csharp Copy code using System; public class B { public B(int id) { Console.WriteLine(id); } } public class A : B { public A() : base(12) { Console.WriteLine("Default constructor..."); } public static void Main(string[] args) { A a = new A(); } } Output: kotlin Copy code 12 Default constructor... ________________________________________ QUESTION 6: csharp Copy code using System; public class B { public B(int id) { Console.WriteLine(id); } } public class A : B { public A() { Console.WriteLine("Default constructor..."); } public static void Main(string[] args) { A a = new A(); } } Output: javascript Copy code Error: Base class constructor with arguments must be called explicitly. Day 6: String Functions, Literal vs Non-literal Strings, Mutable vs Immutable Strings ________________________________________ Theory Questions 1. What is meant by a string? o A string is a sequence of characters enclosed in double quotes (""). It is used to represent textual data in programming languages. 2. How to find the length of a string? o In C#, you can find the length of a string using the Length property: csharp Copy code string str = "Hello"; int length = str.Length; // Returns 5 3. How to find a particular character in a string? o You can use the IndexOf() method to find the index of a particular character in a string: csharp Copy code string str = "Hello"; int index = str.IndexOf('e'); // Returns 1 4. How to split the string? o You can use the Split() method to divide a string into an array based on a delimiter: csharp Copy code string str = "Hello World"; string[] words = str.Split(' '); // Splits into ["Hello", "World"] 5. What is the difference between literal and non-literal strings? o Literal String: A string that is directly assigned in code using double quotes. For example, "Hello". o Non-literal String: A string that is created at runtime, often using string manipulation methods or input from users. 6. What is a mutable and immutable string? o Mutable String: A string whose content can be changed after it is created. Example: StringBuilder and StringBuffer. o Immutable String: A string whose content cannot be changed once it is created. Example: string in C# (equivalent to String in Java). 7. Difference between StringBuilder and StringBuffer? o Both StringBuilder and StringBuffer are used to create mutable strings in C#, but:  StringBuffer: Thread-safe but slower.  StringBuilder: Not thread-safe but faster in performance. 8. Method name to identify memory location? o In C#, you can use the GetHashCode() method to identify the memory location (or identity) of an object. 9. What are the string functions available in C#? o Some common string functions in C#:  Length: Returns the length of the string.  IndexOf(): Finds the index of a character or substring.  Split(): Divides a string into parts.  Substring(): Extracts a portion of a string.  ToLower(), ToUpper(): Converts a string to lowercase or uppercase.  Replace(): Replaces characters or substrings. 10. What is the difference between charAt() and contains() method? o charAt(): In C#, this method is String[index]. It returns the character at a specific index. o contains(): Checks if a substring exists within a string and returns true or false. 11. What is the return type of compareTo()? o The return type of compareTo() is an int. It compares two strings lexicographically. 12. Where are literal strings and non-literal strings stored? o Literal Strings are stored in a special memory area called the string pool (or intern pool). o Non-literal Strings are stored in the heap memory. 13. What is meant by ASCII value? o ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns numerical values (between 0 and 127) to characters. For example, the ASCII value of 'A' is 65. ________________________________________ Programs ________________________________________ QUESTION 1: Description: Find the length of the below strings. csharp Copy code string str1 = "GreensTechnology"; string str2 = "SeleniumAutomationtool"; string str3 = "velmurugan"; string str4 = "j a v a p r o g r a m"; string str5 = "9095484678"; Console.WriteLine(str1.Length); // 16 Console.WriteLine(str2.Length); // 22 Console.WriteLine(str3.Length); // 10 Console.WriteLine(str4.Length); // 21 Console.WriteLine(str5.Length); // 10 ________________________________________ QUESTION 2: Description: Find the particular character index in the given string. csharp Copy code string str1 = "GreensTechnology"; Console.WriteLine(str1.LastIndexOf('o')); // 14 string str2 = "SeleniumAutomationtool"; Console.WriteLine(str2.IndexOf('o')); // 4 string str3 = "Velmurugan"; Console.WriteLine(str3.IndexOf('n')); // 9 string str4 = "j a v a p r o g r a m"; Console.WriteLine(str4.LastIndexOf(' ')); // 17 string str5 = "9095484678"; Console.WriteLine(str5.IndexOf('8')); // 4 ________________________________________ QUESTION 3: Description: Find the particular character in the given string. csharp Copy code string str1 = "GreensTechnology"; Console.WriteLine(str1[7]); // h string str2 = "SeleniumAutomationtool"; Console.WriteLine(str2[4]); // o string str3 = "velmurugan"; Console.WriteLine(str3[6]); // u string str4 = "j a v a p r o g r a m"; Console.WriteLine(str4[6]); // p string str5 = "9095484678"; Console.WriteLine(str5[6]); // 7 ________________________________________ QUESTION 4: Description: Get two inputs from the user and check for equality. csharp Copy code string str1 = "Java"; string str2 = "Java"; Console.WriteLine(str1.Equals(str2)); // True string str3 = "Java"; string str4 = "java"; Console.WriteLine(str3.Equals(str4)); // False string str5 = "Green Technology"; string str6 = "GreenTechnology"; Console.WriteLine(str5.Equals(str6)); // False Console.WriteLine(str1.Equals(str2, StringComparison.OrdinalIgnoreCase)); // True ________________________________________ QUESTION 5: ________________________________________ QUESTION 5.1: Description: Get the email ID from the user and verify if '@' is present. csharp Copy code string email = "velmurugank451@gmail.com"; if (email.Contains("@")) { Console.WriteLine("Valid email id"); } else { Console.WriteLine("Invalid email id"); } ________________________________________ QUESTION 5.2: Description: Get the address from the user and verify if "pincode" is present. csharp Copy code string address = "5-35-2a,venkatesh nivas,Aruppukottai"; if (address.Contains("pincode")) { Console.WriteLine("Valid address"); } else { Console.WriteLine("Invalid address"); } ________________________________________ QUESTION 5.3: Description: Verify if '@' is present in the email and return true or false. csharp Copy code string email = "Nishakerala24@gmail.com"; bool result = email.Contains("@"); Console.WriteLine(result); // True or False ________________________________________ QUESTION 5.4: Description: Verify if a phone number contains any characters. csharp Copy code string phone = "90954a6o78"; if (phone.Any(c => !Char.IsDigit(c))) { Console.WriteLine("Invalid number"); } else { Console.WriteLine("Valid number"); } ________________________________________ QUESTION 6: Description: Check if a phone number exceeds 10 digits. csharp Copy code string phone = "89034256972365"; if (phone.Length > 10) { Console.WriteLine("Invalid number"); } else { Console.WriteLine("Valid number"); } ________________________________________ QUESTION 7: ________________________________________ QUESTION 7.1: csharp Copy code string str = "Welcome to class java"; string newStr = str.Replace("java", "sql"); Console.WriteLine(newStr); // "Welcome to class sql" ________________________________________ QUESTION 7.2: csharp Copy code string str = "Greens Adayar"; string newStr = str.Replace("Adayar", "Omr"); Console.WriteLine(newStr); // "Greens Omr" ________________________________________ QUESTION 7.3: csharp Copy code string str = "Welcome to java class"; string newStr = str.Replace(" ", "#"); Console.WriteLine(newStr); // "Welcome#to#java#class" ________________________________________ QUESTION 7.4: csharp Copy code string email = "Nishakerala24@gmail.com"; string newEmail = email.Replace("gmail", "yahoo"); Console.WriteLine(newEmail); // "Nishakerala24@yahoo.com" ________________________________________ QUESTION 7.5: csharp Copy code string address = "5-35-2a,venkatesh nivas,Aruppukottai,pincode-626101"; string newAddress = address.Replace("pincode", ""); Console.WriteLine(newAddress); // "5-35-2a,venkatesh nivas,Aruppukottai," ________________________________________ QUESTION 8: ________________________________________ QUESTION 8.1: csharp Copy code string input = "NISHANTHI"; Console.WriteLine(input.ToLower()); // "nishanthi" DAY 7: Arrays & Collections (ArrayList only) Theory Questions 1. What do you mean by an array and how to create an array? o An array is a data structure that holds a fixed number of elements of the same data type. It is created using the syntax: dataType[] arrayName = new dataType[size];. 2. Can you change the size of an array once created? o No, arrays in Java have a fixed size once they are created. You cannot change the size of an array after initialization. 3. Is it legal to initialize an array like int i[] = {1, 2, 3, 4, 5};? o Yes, it is legal. This is an example of array initialization with a specific set of values. 4. What are the advantages and disadvantages of arrays? o Advantages:  Fast access to elements.  Simple data structure. o Disadvantages:  Fixed size.  Cannot store elements of different data types. 5. Can we change the size of an array at runtime? o No, the size of an array is fixed at the time of creation. To change the size, you must create a new array. 6. Can you declare an array without assigning the size of the array? o No, the size must be specified when creating an array unless it is initialized with values. 7. What is the default value of an array? o For numeric types (e.g., int, float), the default value is 0. For objects, the default value is null. 8. How to print elements of an array? o Use a loop (e.g., for or for-each) to print each element of the array. 9. How to compare two arrays? o You can use the Arrays.equals() method or Arrays.deepEquals() for multidimensional arrays. 10. How to sort an array? o Use Arrays.sort() to sort the array. 11. Can we declare array size as a negative number? o No, array size cannot be negative. 12. Can we add or delete an element after assigning an array? o No, arrays have a fixed size. You cannot add or remove elements dynamically. 13. Can we use Generics with arrays? o No, generics do not work with arrays in Java. You can use collections like ArrayList for generic support. 14. What is a collection and explain about types? o A collection is a group of objects. The main types are:  List: Ordered collection (e.g., ArrayList, LinkedList).  Set: Unordered collection (e.g., HashSet, TreeSet).  Queue: Collection designed for holding elements to be processed (e.g., PriorityQueue).  Map: A collection of key-value pairs (e.g., HashMap, TreeMap). 15. What is the difference between ArrayList and Vector? o ArrayList: It is not synchronized and is more efficient in terms of performance. o Vector: It is synchronized, making it slower than ArrayList. 16. What is the difference between ArrayList and LinkedList? o ArrayList: It uses a dynamic array for storing elements, offering fast access but slower insertions and deletions. o LinkedList: It uses a doubly linked list for storage, making insertions and deletions faster but slower access. 17. How to convert Array to List and List to Array? o Array to List: Use Arrays.asList(array). o List to Array: Use list.toArray(new Type[0]). ________________________________________ Program Output Questions QUESTION 1: Write a Java program to sum values of an array: java Copy code int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int sum = 0; for (int num : a) { sum += num; } System.out.println(sum); // Output: 55 QUESTION 2: Write a Java program to calculate the average value of array elements: java Copy code int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int sum = 0; for (int num : a) { sum += num; } double average = sum / (double) a.length; System.out.println("average = " + average); // Output: average = 7.0 QUESTION 3: Write a Java program to remove duplicates from an array: java Copy code int a[] = {10, 10, 20, 50, 60, 80, 60, 50}; Set set = new HashSet<>(); for (int num : a) { set.add(num); } System.out.println(set); // Output: [10, 20, 50, 60, 80] ________________________________________ List Operations QUESTION 4.1: Create a new ArrayList with values and find the length: java Copy code List list = new ArrayList<>(Arrays.asList(10, 20, 30, 90, 10, 10, 40, 50)); System.out.println(list.size()); // Output: 8 QUESTION 4.2: Create a new LinkedList with values and find the length: java Copy code List list = new LinkedList<>(Arrays.asList(100, 200, 300, 400, 500, 600, 700)); System.out.println(list.size()); // Output: 7 QUESTION 4.3: Create a new Vector with values and find the length: java Copy code List list = new Vector<>(Arrays.asList(105, 205, 305, 405, 505, 605, 705, 805)); System.out.println(list.size()); // Output: 8 QUESTION 5.1: Get the first index value of 10: java Copy code List list = new ArrayList<>(Arrays.asList(10, 20, 30, 90)); System.out.println(list.indexOf(10)); // Output: 0 QUESTION 5.2: Get the last index value of 10: java Copy code List list = new ArrayList<>(Arrays.asList(10, 20, 30, 90, 10, 10, 40, 50)); System.out.println(list.lastIndexOf(10)); // Output: 5 QUESTION 5.3: Get the index value of 50: java Copy code List list = new ArrayList<>(Arrays.asList(10, 20, 30, 90, 10, 10, 40, 50)); System.out.println(list.indexOf(50)); // Output: 7 ________________________________________ Adding, Replacing, and Removing Elements QUESTION 8.1: Add value 50 at the 2nd index: java Copy code List list = new ArrayList<>(Arrays.asList(10, 20, 30, 90, 10, 10, 40, 50)); list.add(2, 50); System.out.println(list); // Output: [10, 20, 50, 30, 90, 10, 10, 40, 50] QUESTION 9.1: Replace value 300 with 350: java Copy code List list = new ArrayList<>(Arrays.asList(100, 200, 300, 400, 500, 600, 700)); int index = list.indexOf(300); list.set(index, 350); System.out.println(list); // Output: [100, 200, 350, 400, 500, 600, 700] DAY 8 - C# Learners' Questions and Program Explanations Theory Questions: 1. Describe the Collections type hierarchy. What are the main interfaces, and what are the differences between them? o In C#, collections are part of the System.Collections namespace. The main interfaces in the hierarchy are:  IEnumerable: A basic interface for all collections. It allows iteration over a collection.  ICollection: Inherits from IEnumerable, adds methods for adding, removing, and managing collections.  IList: Inherits from ICollection, represents a collection of objects that can be accessed by index.  IDictionary: Represents a collection of key/value pairs. Differences: o IList allows indexed access to elements, while IEnumerable and ICollection focus more on iteration. o IDictionary is designed for collections of key/value pairs, while other interfaces are for general collections of objects. 2. Explain about user-defined lists? o In C#, a user-defined list can be created by implementing the IList interface or by using List. These allow users to create custom collections that meet specific needs. For example, a custom list could have additional methods for sorting or filtering the data. 3. Mention what is Linked List? o A LinkedList in C# is a collection of nodes where each node contains a data element and references to the next and previous nodes. It allows fast insertions and deletions, especially in the middle of the list. 4. What is difference between Set and List? o List: An ordered collection that allows duplicate elements and maintains the order of insertion. o Set: An unordered collection that does not allow duplicate elements. In C#, HashSet and SortedSet are implementations of sets. 5. What is the difference between HashSet and TreeSet? o HashSet: Implements the ISet interface and uses a hash table for storage. It provides fast operations for adding, removing, and checking for existence but does not guarantee any specific order of elements. o TreeSet (in C# known as SortedSet): Implements ISet and uses a tree structure (usually a red-black tree). It guarantees that elements are always sorted according to a specified comparer or default sorting order. 6. Difference between Enumerator, Iterator, and List Iterator o Enumerator: A C# specific term for the object that allows iteration over a collection using MoveNext() and Current. o Iterator: A more general concept of a design pattern used for traversing a collection. o List Iterator: A more specialized iterator for lists that can iterate both forward and backward (not available in C# directly, but can be emulated using List and ListIterator in some cases). 7. How to convert List into Set? o To convert a List into a Set, you can use the HashSet constructor or AddRange() method. Example: csharp Copy code List list = new List { 1, 2, 2, 3, 4 }; HashSet set = new HashSet(list); ________________________________________ Programming Questions: QUESTION 1.1: Description: Create a HashSet for the following values. csharp Copy code List list = new List { 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20 }; HashSet hashSet = new HashSet(list); QUESTION 1.2: Description: Create a LinkedHashSet for the following values. In C#, the equivalent of LinkedHashSet is LinkedList because the LinkedHashSet concept doesn't exist directly. csharp Copy code List list = new List { 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20 }; LinkedList linkedList = new LinkedList(list.Distinct()); QUESTION 1.3: Description: Create a TreeSet for the following values. In C#, use SortedSet to achieve a similar effect: csharp Copy code List list = new List { 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20 }; SortedSet sortedSet = new SortedSet(list); ________________________________________ QUESTION 2.1: Description: Convert the list into a set using AddAll() method. csharp Copy code List list = new List { 10, 20, 30, 90, 10, 10, 40, 50 }; HashSet set = new HashSet(); set.UnionWith(list); // Equivalent to addAll() in other languages QUESTION 2.2: Description: Convert the below list into a set using AddAll() method. csharp Copy code List list = new List { 105, 205, 305, 405, 505, 605, 705, 805, 505, 605 }; HashSet set = new HashSet(); set.UnionWith(list); QUESTION 2.3: Description: Convert the list into a set using AddAll() method. csharp Copy code List list = new List { 100, 200, 300, 400, 500, 600, 700, 100, 300, 500 }; HashSet set = new HashSet(); set.UnionWith(list); ________________________________________ QUESTION 3.1: Description: Get the each value of set by using enhanced for loop. csharp Copy code HashSet set = new HashSet { 105, 205, 305, 405, 505, 605, 705, 805 }; foreach (var item in set) { Console.WriteLine(item); } QUESTION 3.2: Description: Create a TreeSet and iterate each value in the set by using enhanced for loop. csharp Copy code SortedSet sortedSet = new SortedSet { 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20 }; foreach (var item in sortedSet) { Console.WriteLine(item); } QUESTION 3.3: Description: Create a HashSet and iterate each value in the set by using enhanced for loop. csharp Copy code HashSet hashSet = new HashSet { 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20 }; foreach (var item in hashSet) { Console.WriteLine(item); } ________________________________________ QUESTION 4.1: Description: Create a new HashSet with values and return the common values. csharp Copy code HashSet set1 = new HashSet { 10, 20, 30, 90, 10, 10, 40, 50 }; HashSet set2 = new HashSet { 30, 40, 50, 60, 80 }; set1.IntersectWith(set2); foreach (var item in set1) { Console.WriteLine(item); } QUESTION 4.2: Description: Create a new LinkedHashSet with values and return the common values. csharp Copy code HashSet set1 = new HashSet { 10, 20, 30, 90, 10, 10, 40, 50 }; HashSet set2 = new HashSet { 10, 20, 60, 50, 40, 70, 80, 90 }; set1.IntersectWith(set2); foreach (var item in set1) { Console.WriteLine(item); } QUESTION 4.3: Description: Create a new TreeSet with values and return the common values. csharp Copy code SortedSet set1 = new SortedSet { 10, 20, 30, 40, 50, 60, 70, 80 }; SortedSet set2 = new SortedSet { 100, 200, 300, 400, 500, 600, 700, 8000 }; set1.IntersectWith(set2); foreach (var item in set1) { Console.WriteLine(item); } ________________________________________ QUESTION 5.1: Description: Create a new HashSet with values and perform removeAll() function. csharp Copy code HashSet set1 = new HashSet { 10, 20, 30, 90, 10, 10, 40, 50 }; HashSet set2 = new HashSet { 30, 40, 50, 60, 80 }; set1.ExceptWith(set2); foreach (var item in set1) { Console.WriteLine(item); } QUESTION 5.2: Description: Create a new LinkedHashSet with values and perform removeAll() function. csharp Copy code HashSet set1 = new HashSet { 10, 20, 30, 90, 10, 10, 40, 50 }; HashSet set2 = new HashSet { 10, 20, 60, 50, 40, 70, 80, 90 }; set1.ExceptWith(set2); foreach (var item in set1) { Console.WriteLine(item); } ________________________________________ QUESTION 6: Description: Create a user-defined set and insert 10 employee details. You can create a custom Employee class and insert employee details into a HashSet: csharp Copy code public class Employee { public int EmpId { get; set; } public string Name { get; set; } // Other properties... } HashSet employees = new HashSet(); employees.Add(new Employee { EmpId = 1, Name = "John Doe" }); // Add more employees... QUESTION 7: Description: Create a user-defined set and insert 10 student details. csharp Copy code public class Student { public int StdId { get; set; } public string StdName { get; set; } // Other properties... } HashSet students = new HashSet(); students.Add(new Student { StdId = 1, StdName = "Jane Smith" }); // Add more students... Here's the revised content adapted for C# learners: ________________________________________ DAY 9: 1. Map and Types 2. User-Defined Map ________________________________________ THEORY QUESTIONS: 1. What is a Map in C#? 2. What is the difference between a Dictionary and Hashtable in C#? 3. What is the difference between a Set and a Map in C#? 4. What are the classes that implement the IList interface in C#? 5. Which classes implement the ISet interface in C#? 6. Explain about user-defined Map in C#. 7. How does null behave in the following Maps in C#? o Dictionary: TKey?, TValue? o SortedDictionary: TKey?, TValue? o Hashtable: TKey?, TValue? 8. How do you iterate over a Map in C#? 9. What is the return type of EntrySet in C#? ________________________________________ PRACTICAL QUESTIONS: QUESTION 1.1: • Description: Create a Dictionary with the following key-value pairs: o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: "java", "sql", "oops", "Sql", "oracle", "DB", "selenium", "psql", "Hadoop" QUESTION 1.2: • Description: Create a LinkedHashMap equivalent in C# with the following key-value pairs: o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: 10, 20, 30, 40, 50, 60, 10, 50, 40 QUESTION 1.3: • Description: Create a SortedDictionary equivalent in C# with the following key-value pairs: o Key: '!', '@', '#', '$', '%', '^', '&', '*', '(' o Value: 10, 20, 30, 40, 50, 60, 10, 50, 40 QUESTION 1.4: • Description: Create a Hashtable in C# with the following key-value pairs: o Key: "vel", "Ganesh", "Dinesh", "Vengat", "subash" o Value: "Selenium", "framework", "oracle", "corejava", "jira" ________________________________________ QUESTION 2: QUESTION 2.1: • Description: Create a Dictionary and print only the keys. o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: "java", "sql", "oops", "Sql", "oracle", "DB", "selenium", "psql", "Hadoop" QUESTION 2.2: • Description: Create a SortedDictionary and print only the keys. o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: 10, 20, 30, 40, 50, 60, 10, 50, 40 QUESTION 2.3: • Description: Create a SortedDictionary and print only the keys. o Key: '!', '@', '#', '$', '%', '^', '&', '*', '(' o Value: 10, 20, 30, 40, 50, 60, 10, 50, 409 QUESTION 2.4: • Description: Create a Hashtable and print only the keys. o Key: "vel", "Ganesh", "Dinesh", "Vengat", "subash" o Value: "Selenium", "framework", "oracle", "corejava", "jira" ________________________________________ QUESTION 3: QUESTION 3.1: • Description: Create a Dictionary and print only the values. o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: "java", "sql", "oops", "Sql", "oracle", "DB", "selenium", "psql", "Hadoop" QUESTION 3.2: • Description: Create a SortedDictionary and print only the values. o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: 10, 20, 30, 40, 50, 60, 10, 50, 40 QUESTION 3.3: • Description: Create a SortedDictionary and print only the values. o Key: '!', '@', '#', '$', '%', '^', '&', '*', '(' o Value: 10, 20, 30, 40, 50, 60, 10, 50, 409 QUESTION 3.4: • Description: Create a Hashtable and print only the values. o Key: "vel", "Ganesh", "Dinesh", "Vengat", "subash" o Value: "Selenium", "framework", "oracle", "corejava", "jira" ________________________________________ QUESTION 4: QUESTION 4.1: • Description: Create a Dictionary and iterate using a foreach loop to print the key-value pairs. o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: "java", "sql", "oops", "Sql", "oracle", "DB", "selenium", "psql", "Hadoop" QUESTION 4.2: • Description: Create a SortedDictionary and iterate using a foreach loop to print the key-value pairs. o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: 10, 20, 30, 40, 50, 60, 10, 50, 40 QUESTION 4.3: • Description: Create a SortedDictionary and iterate using a foreach loop to print the key-value pairs. o Key: '!', '@', '#', '$', '%', '^', '&', '*', '(' o Value: 10, 20, 30, 40, 50, 60, 10, 50, 409 QUESTION 4.4: • Description: Create a Hashtable and iterate using a foreach loop to print the key-value pairs. o Key: "vel", "Ganesh", "Dinesh", "Vengat", "subash" o Value: "Selenium", "framework", "oracle", "corejava", "jira" ________________________________________ QUESTION 5: QUESTION 5.1: • Description: Create a Dictionary and iterate using a foreach loop to print the key-value combinations. o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: "java", "sql", "oops", "Sql", "oracle", "DB", "selenium", "psql", "Hadoop" QUESTION 5.2: • Description: Create a SortedDictionary and iterate using a foreach loop to print the key-value combinations. o Key: 10, 20, 30, 40, 50, 60, 10, 50, 40 o Value: 10, 20, 30, 40, 50, 60, 10, 50, 40 QUESTION 5.3: • Description: Create a SortedDictionary and iterate using a foreach loop to print the key-value combinations. o Key: '!', '@', '#', '$', '%', '^', '&', '*', '(' o Value: 10, 20, 30, 40, 50, 60, 10, 50, 409 QUESTION 5.4: • Description: Create a Hashtable and iterate using a foreach loop to print the key-value combinations. o Key: "vel", "Ganesh", "Dinesh", "Vengat", "subash" o Value: "Selenium", "framework", "oracle", "corejava", "jira" ________________________________________ QUESTION 6: • Description: Create a user-defined Map in C# and insert 10 employee details. o Key: empId, name, phone, address, dob, doj, email, gender, salary o Use Dictionary or Dictionary for storing the data of each employee. QUESTION 7: • Description: Create a user-defined Map in C# and insert 10 student details. o Key: stdId, stdName, stdPhone, address, dob, email, gender o Use Dictionary or Dictionary for storing the data of each student. DAY 10: 1. Exception Handling 2. Throw and Throws 3. User-Defined Exceptions ________________________________________ THEORY QUESTIONS: 1. What is an exception in C#? 2. Explain the types of exceptions in C#. 3. What is the difference between checked and unchecked exceptions in C#? 4. What are the differences between exceptions and errors in C#? 5. What is the base class for exceptions and errors in C#? 6. In which namespace are exceptions defined in C#? 7. What is the throw keyword in C#? 8. Can we have a try block without a catch block in C#? 9. Can we write multiple catch blocks under a single try block in C#? 10. How do you write a user-defined exception (custom exception) in C#? 11. What are the different ways to print an exception message to the console in C#? 12. What are the differences between finally, Dispose(), and Finalize() in C#? 13. Can we write a return statement in a try and catch block in C#? 14. Can we write a return statement in a finally block in C#? 15. What are the differences between throw and throws in C#? 16. What are the exception handling keywords in C#? 17. Explain the exception handling hierarchy in C#. 18. How do you create a custom exception in C#? ________________________________________ PRACTICAL QUESTIONS: QUESTION 1: • Description: Find the output for the following program: csharp Copy code using System; class Test { static void Main() { try { Console.Write("1"); int sum = 9 / 0; Console.Write("2"); } catch (DivideByZeroException e) { Console.Write("3"); } catch (Exception e) { Console.Write("4"); } finally { Console.Write("5"); } } } ________________________________________ QUESTION 2: • Description: Find the output for the following program: csharp Copy code using System; class Test { private void m1() { m2(); Console.Write("1"); } private void m2() { m3(); Console.Write("2"); } private void m3() { Console.Write("3"); try { int sum = 4 / 0; Console.Write("4"); } catch (DivideByZeroException e) { Console.Write("5"); } Console.Write("7"); } static void Main() { Test obj = new Test(); obj.m1(); } } ________________________________________ QUESTION 3: • Description: Find the output for the following program: csharp Copy code using System; class Test { static void Main() { try { Console.Write("1"); int data = 5 / 0; } catch (DivideByZeroException e) { Console.Write("2"); Environment.Exit(0); } finally { Console.Write("3"); } Console.Write("4"); } } ________________________________________ QUESTION 4: • Description: Find the output for the following program: csharp Copy code using System; class Test { static void Main() { try { Console.Write("1"); int data = 5 / 0; } catch (DivideByZeroException e) { Exception obj = new Exception("Sample"); try { throw obj; } catch (Exception e1) { Console.Write("8"); } } finally { Console.Write("3"); } Console.Write("4"); } } ________________________________________ QUESTION 5: • Description: Find the output for the following program: csharp Copy code using System; using System.IO; class Test { static void Main() { try { Console.Write("1"); int value = 10 / 0; throw new IOException(); } catch (EndOfStreamException e) { Console.Write("2"); } catch (DivideByZeroException e) { Console.Write("3"); } catch (NullReferenceException e) { Console.Write("4"); } catch (IOException e) { Console.Write("5"); } catch (Exception e) { Console.Write("6"); } } } ________________________________________ Key Changes for C# Learners: • Exceptions in C#: C# uses try, catch, finally blocks for exception handling. Instead of Java’s throw and throws, C# uses throw for explicitly throwing exceptions, and there is no throws keyword in C#. • Checked and Unchecked Exceptions: In C#, all exceptions are unchecked, meaning there is no compile-time checking for exceptions (like Java's checked exceptions). • Finally Block: In C#, finally is used to execute code after the try-catch, even if an exception is thrown. • Custom Exception: C# custom exceptions are created by inheriting from the Exception class and can be thrown using the throw keyword.