Recap - HashSet
Teil des Abschnitts Logik & Ablauf der C#-Journey von Coddy — Lektion 61 von 66.
Aufgabe
EinfachErstellen Sie eine Methode namens ProcessHashSet, die mehrere Operationen an einem HashSet durchführt:
- Erstellen Sie ein neues HashSet von Strings
- Fügen Sie drei Frucht-Namen hinzu: "Apple", "Banana" und "Orange"
- Geben Sie aus, ob "Mango" im Set existiert (verwenden Sie das Format: "Contains Mango: True/False")
- Versuchen Sie, "Apple" erneut hinzuzufügen, und geben Sie aus, ob es hinzugefügt wurde (verwenden Sie das Format: "Added Apple again: True/False")
- Entfernen Sie "Banana" und geben Sie aus, ob es erfolgreich entfernt wurde (verwenden Sie das Format: "Removed Banana: True/False")
- Geben Sie die aktuelle Anzahl der Elemente aus (verwenden Sie das Format: "Count: N")
- Geben Sie das HashSet zurück
Probier es selbst
using System;
using System.Collections.Generic;
class Program
{
public static HashSet<string> ProcessHashSet()
{
// Schreibe hier deinen Code
return null;
}
static void Main(string[] args)
{
HashSet<string> result = ProcessHashSet();
if (result != null)
{
Console.WriteLine(string.Join(", ", result));
}
}
}Alle Lektionen in Logik & Ablauf
1Multi-dimensional Arrays
2D Arrays BasicsDeclaring and Initializing 2DAccessing 2D Array ElementsNested Loops with 2D ArraysJagged ArraysCommon Matrix OperationsRecap - Multi-dimensional4Flow Control Techniques
Early ReturnsGuard ClausesJump Statements (goto)Break and ContinueFlatten Nested Conditionals7Logical Operators Advanced
Short-Circuit EvaluationConditional Logical OperatorsOperator PrecedenceRecap - Advanced Operators2Advanced Decision Making
Multiple ConditionsComplex Boolean LogicIf vs. Switch ComparisonNested Switch StatementsRecap - Advanced Decisions5Exception Handling
Try-Catch BasicsException TypesMultiple Catch BlocksWorking with FilesFinally BlockUsing vs. Try-FinallyCustom ExceptionsRecap - Error Handling8Data Analysis System
Data Collection SetupData Entry Logic11HashSet Part 1
What is a HashSet?Adding an ElementRemoving an ElementChecking if an Element ExistsEmpty and SizeRecap - HashSet3Loop Enhancements
Loop PerformanceIterating ComplexEach Loop TypeRefactoring LoopsRecap - Optimized Loops6Null Handling
Null Reference BasicsNullable Value TypesNull Checking PatternsDefensive ProgrammingRecap - Null Safety