Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

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

Tech Apr 30 22

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

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

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

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