Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
YouTube Security VideosTechLinked: Apple says no more upgradeability(25.09.2026 um 01:02 Uhr)
•
Podcasts & Audio BriefingsiPhone 18, iPhone Duo und AirPods auf dem Prüfstand | CHIP.Chat #44(25.09.2026 um 00:00 Uhr)
•
YouTube Security VideosGoogle Cloud Tech: A Developer’s Guide to Gemini 3.5 Transcribe(25.09.2026 um 01:00 Uhr)
••••••••
YouTube Security VideosTechLinked: Apple says no more upgradeability(25.09.2026 um 01:02 Uhr)
•
Podcasts & Audio BriefingsiPhone 18, iPhone Duo und AirPods auf dem Prüfstand | CHIP.Chat #44(25.09.2026 um 00:00 Uhr)
•
YouTube Security VideosGoogle Cloud Tech: A Developer’s Guide to Gemini 3.5 Transcribe(25.09.2026 um 01:00 Uhr)
••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Getting Started with LINQ in C# (1/3)

Language Integrated Query or LINQ is a C# feature that allows you to query different data sources, such as: In memory collections (arrays, lists, dictionaries) SQL collections XML collections using a unified language syntax. There are…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Language Integrated Query or LINQ is a C# feature that allows you to query different data sources, such as:




  • In memory collections (arrays, lists, dictionaries)

  • SQL collections

  • XML collections



using a unified language syntax.



There are two ways to use LINQ:





  • Query syntax consist of a set of query keywords defined into the .NET Framework that resemble SQL-Like commands.


  • Method syntax consist of operator functions (extension methods) chained together using a declarative programming paradigm.



For this tutorial we'll use LINQ Extension method syntax.






Where can we use LINQ?



Language Integrated Query syntax works with any type of collection in C# that implements the IEnumerable interface, such as arrays, lists, dictionaries, etc. Simply put, whenever you see a type IEnumerable or type that implements the IEnumerable, you can use LINQ.






Setup



To speed things up, I've already created a collection ot students in the JSON file. The Gist I wrote will explain how to import the JSON data into a C# collection.



Each student is a class containing properties:




public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Country { get; set; }
}









var student = new LINQTutorial();
List<Student> students = student.GetStudents();






The method GetStudents() on the student instance retrieves a collection of students populated using the JSON file. More in the Gist.



Now let's make use of various LINQ Operators to query the students data.






FILTERS






First & Last



The First() operator returns the first record in the collection:




var firstStudent = students.First();

Console.WriteLine($"Name: {firstStudent.Name}, Age: {firstStudent.Age}, Country: {firstStudent.Country}");
// Name: Mirza, Age: 18, Country: Bosnia






The opposite of First() is the Last() operator that returns the last record:




var lastStudent = students.Last();

Console.WriteLine($"Name: {lastStudent.Name}, Age: {lastStudent.Age}, Country: {lastStudent.Country}");
// Name: Amy, Age: 21, Country: USA






This is one way of using First() and Last() operators. The LINQ operators have an overload method that accepts a predicate and return the record/s that match the condition inside.




var firstStudent = students.First(x => x.Age == 19);

Console.WriteLine($"Name: {firstStudent.Name}, Age: {firstStudent.Age}, Country: {firstStudent.Country}");
// Name: Alan, Age: 19, Country: UK

var lastStudent = students.Last(x => x.Age == 20);

Console.WriteLine($"Name: {lastStudent.Name}, Age: {lastStudent.Age}, Country: {lastStudent.Country}");
// Name: Raj, Age: 20, Country: India









First/Last Or Default



What would happen if we'd query for first student with the age of 100?




var firstStudent = students.First(x => x.Age == 100);






Because there is no record of a student with age 100, the C# program execution will stop and throw an exception:




System.InvalidOperationException: Sequence contains no matching element






To prevent this we can use the FirstOrDefault() operator that works just the same as the First(), with an exception that it returns null if no record meets the condition.




var firstStudent = students.FirstOrDefault(x => x.Age == 19); // {...} 
var nonExistingStudent = students.FirstOrDefault(x => x.Age == 100); // null






The same applies for the Last() and LastOrDefault() operators.






ElementAt



This method is used to retrieve an element at a specific index.




var fifthStudent = students.ElementAt(4);

Console.WriteLine($"Name: {fifthStudent.Name}, Age: {fifthStudent.Age}");
// Name: Farook, Age: 18






That said, if you use an index that is not present, the exception will be thrown:




var nonExistingStudent = students.ElementAt(100);









System.ArgumentOutOfRangeException: Index was out of range. 






So it's safer to use ElementAtOrDefault:




var nonExistingStudent = students.ElementAtOrDefault(100); // null









Where



The Where() operator is used to filter multiple elements. The output is an array of all elements that meet a specified criteria.




var studentsFromBosnia = students.Where(x => x.Country == "Bosnia");

foreach (var student in studentsFromBosnia)
{
Console.WriteLine($"Name: {student.Name}, Age: {student.Age}");
}
// Name: Mirza, Age: 18
// Name: Armin, Age: 20






One thing to note about studentsFromBosnia is that is not of type List<Student>, but rather IEnumerable<Student>. The LINQ works in either way.



However, if you need to pass this collection to a method that takes an array or a list as a parameter, you can cast an IEnumerable to derived types.






BUILDERS



To convert an IEnumerable to an array simply do:




var studentsArray = studentsFromBosnia.ToArray(); 
// Array<Student>






To convert an IEnumerable to a list simply do:




var studentsList = studentsFromBosnia.ToList(); 
// List<Student>






To convert an IEnumerable collection to a dictionary, first restructure the data into an anonymous key-value pair object and then covert the object to dictionary.




var studentsDictionary = studentsFromBosnia
.Select((stud, index) => new { index, stud }) // creating an anonymous object
.ToDictionary(x => x.index, x => x.stud); // converting object to dictionary
// Dictionary<int, Student>









PROJECTION






Select



The Select operator is used to retrieve a list of specific properties from an IEnumerable, in this case List. For example, let's say we want to pick names of all students:




IEnumerable<string> names = students.Select(s => s.Name);

foreach (var name in names)
{
Console.WriteLine(name);
// Mirza, Armin, Alan, Seid...
}






Or a combination of properties (Name & Country):




var customList = students.Select(s => new { Name = s.Name, Country = s.Country });

foreach (var student in customList)
{
Console.WriteLine($"Name: {student.Name}, Country: {student.Country}");
}






custom-select






SORTING






OrderBy



The OrderBy operator is used to order elements in the collections. For example, if we'd take ages of all students and put them into a collection:




var ages = students.Select(s => s.Age);






The outcome would be a collection sorted in the order the students were created. Applying the OrderBy, the ages are shown from smallest to largest:




var agesInOrder = students.OrderBy(s => s.Age).Select(s => s.Age);
// [18, 18, 18, 19, 19, 20, 20, 21, 22, 24]






It's clear that we have duplicate elements. We can fix that using the Distinct() operator:




var agesInOrder = students.OrderBy(s => s.Age).Select(s => s.Age).Distint();
// [18, 19,20, 21, 22, 24]






The OrderBy operator can also be applied after the Select:




var agesInOrder = students
.Select(s => s.Age)
.OrderBy(s => s) // sort by values in the collection (ages)
.Distinct();
// [18, 19,20, 21, 22, 24]






In this instance, the ordering by ages is still hapening, but because we've already filtered the ages in the previous line, the OrderBy has less work to do.






OrderByDescending



The OrderbyDescending is doing the same but in the reversed order:




var agesInReverseOrder = students
.Select(s => s.Age)
.OrderByDescending(s => s)
.Distinct();
// [24, 22, 21, 20, 19, 18]









ThenBy, ThenByDescending



The ThenBy operator is used to apply the additional sorting after the OrderBy.




var orderedByAgeAndCountry = students
.OrderBy(s => s.Age)
.ThenBy(s => s.Country)
.Select(s => s.Name);
// ["Mirza", "Eddy", "Farook", "Abdurahman", "Alan"...]

var orderedByAgeAndCountry2 = students
.OrderBy(s => s.Age)
.ThenByDescending(s => s.Country)
.Select(s => s.Name);
// ["Farook", "Eddy", "Mirza", ...]






In the coming parts we'll dive deeper into LINQ. Don't forget to hit the follow button. Also, follow me on Twitter to stay up to date with my upcoming content.



Bye for now 👋

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - Getting Started with LINQ in C# (1/3)
id: a32b5fd2-186d-4d5b-9222-d50ded24d5d6
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "Getting Started with LINQ in C" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Getting Started with LINQ in C 13")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Getting Started with LINQ in C 13*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Getting Started with LINQ in C 13"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Getting Started with LINQ in C# (1/3).... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Getting Started with LINQ in C# (1/3)

Thematisch verwandte Begriffe: Getting, Started, with, LINQ · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-87722 | Uncontrolled Resource Consumption (CWE-400 / CWE-1333) in regex search q…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...
↗ Original-Quelle