Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Core C# Concepts: Arrays, Multithreading, Internal Access, LINQ, and HttpClient

Tech 1

C# Arrays

Arrays in C# are fixed-size data structures that store elements of the same type. They are declared with a specific size and type.

int[] numbers = new int[] { 10, 20, 30, 40, 50 };
int first = numbers[0];
int count = numbers.Length;

C# Multithreading

Multithreading enables concurrent execution in C#. The Thread class and the Task class are commonly used.

System.Threading.Thread thread = new System.Threading.Thread(() =>
{
    Console.WriteLine("Thread running");
});
thread.Start();
thread.Join();

Task task = Task.Run(() => Console.WriteLine("Task running"));
task.Wait();

C# internal Keyword

The internal access modifier restricts visbiility to within the same assembly.

internal class RestrictedClass
{
    public void DoWork() { }
}

C# LINQ

Language Integrated Query (LINQ) provides a SQL-like syntax for querying collections.

int[] data = { 1, 2, 3, 4, 5 };
var evenValues = from d in data
                 where d % 2 == 0
                 select d;

foreach (int v in evenValues)
{
    Console.WriteLine(v);
}

C# HttpClient Usage

HttpClient is used to send HTTP requests and receive responses asynchronously.

using (HttpClient client = new HttpClient())
{
    HttpResponseMessage response = await client.GetAsync("https://example.com/api/data");
    if (response.IsSuccessStatusCode)
    {
        string content = await response.Content.ReadAsStringAsync();
        Console.WriteLine(content);
    }
}

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.