Join Query
using System;
using [Link];
using [Link];
public class Program
{
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
}
public class Department
{
public int DepartmentId { get; set; }
public string DepartmentName { get; set; }
public int EmployeeId { get; set; }
}
public static void Main()
{
List<Employee> employees = new List<Employee>
{
new Employee { EmployeeId = 1, Name = "John" },
new Employee { EmployeeId = 2, Name = "Jane" },
new Employee { EmployeeId = 3, Name = "Doe" }
};
List<Department> departments = new List<Department>
{
new Department { DepartmentId = 1, DepartmentName = "HR", EmployeeId =
1 },
new Department { DepartmentId = 2, DepartmentName = "Finance",
EmployeeId = 2 },
new Department { DepartmentId = 3, DepartmentName = "IT", EmployeeId =
3 }
};
var query = from emp in employees
join dept in departments on [Link] equals
[Link]
select new
{
EmployeeName = [Link],
DepartmentName = [Link]
};
foreach (var item in query)
{
[Link]($"Employee: {[Link]}, Department:
{[Link]}");
}
}
}
2. StreamWriter
namespace JoinQuery;
using System;
using [Link];
public class StringReaderWriterExample
{
public static void Main()
{
string sampleText = "Hello\nWorld\nWelcome to .NET!";
// Using StringReader to read from the string
using (StringReader reader = new StringReader(sampleText))
{
string line;
while ((line = [Link]()) != null)
{
[Link]($"Read line: {line}");
}
}
// Using StringWriter to write to a string
using (StringWriter writer = new StringWriter())
{
[Link]("Hello");
[Link]("World");
[Link]("Welcome to .NET!");
string result = [Link]();
[Link]($"Written text:\n{result}");
}
}
}
3 Threading
using System;
using [Link];
namespace ThreadSyncExample
{
class Program
{
private static readonly object _lockObject = new object();
private static int _counter = 0;
static void Main(string[] args)
{
Thread thread1 = new Thread(IncrementCounter);
Thread thread2 = new Thread(IncrementCounter);
[Link]();
[Link]();
[Link]();
[Link]();
[Link]($"Final Counter Value: {_counter}");
}
private static void IncrementCounter()
{
for (int i = 0; i < 1000; i++)
{
lock (_lockObject)
{
_counter++;
}
}
}
}
}