🟣

C#: Fundamentals & .NET Core

99 cards · 🇺🇸 English

Core C# syntax, types, and .NET Core concepts in one deck.

Study all 99 cards for free

Flashcards, quizzes, pixel-art games and a daily review that remembers for you.

Study this deck free

Try the first 10 cards

1 / 10
Question

C# and who created it

Knew itLearning

Tap the card for the answer · swipe right if you knew it, left if not

Already have an account? Sign in

Cards

  1. 1C# and who created it
    C# (C Sharp) is a general-purpose, object-oriented programming language created by Microsoft (Anders Hejlsberg) in 2000. It runs on the .NET platform (Common Language Infrastructure)
  2. 2Two main type categories in C#
    Value types: stored on stack, direct data storage (int, float, struct, enum) Reference types: stored on heap, store references (class, string, array, object)
  3. 3Boxing and unboxing in C#
    Boxing: converting value type to reference type (implicit) int foo = 42; object bar = foo; // boxed Unboxing: converting reference back to value type (explicit) int foo2 = (int)bar; // unboxed
  4. 4var vs dynamic
    var: compile-time type inference (type determined at compile time, then strongly typed) dynamic: runtime type checking (type resolved at runtime, bypasses compile-time checks)
  5. 5Write a basic C# Hello World program (modern syntax)
    // C# 9+ top-level statements Console.WriteLine("Hello, World!"); // C# 8 and earlier: using System; class Program { static void Main() { Console.WriteLine("Hello, World!"); } }
  6. 6struct vs class
    struct: value type, stack-allocated, no inheritance (except interfaces), pass-by-copy class: reference type, heap-allocated, supports inheritance, pass-by-reference
  7. 7Properties in C#
    Encapsulated fields with get/set accessors: public string Name { get; set; } Auto-property (C# 3+): public int Age { get; private set; } With backing field: private string _name; public string Name { get => _name; set => _name = value; }
  8. 8Delegate in C#
    A type-safe function pointer that references methods. Used for callbacks, events: delegate void MyDelegate(string msg); MyDelegate del = Console.WriteLine; del("Hello");
  9. 9ref vs out parameters
    ref: variable must be initialized before passing, can read and modify out: variable doesn't need initialization, must be assigned before method returns Both pass by reference
  10. 10Events in C#
    Special delegates for publisher-subscriber pattern: public event EventHandler MyEvent; MyEvent += Handler; // subscribe MyEvent?.Invoke(this, EventArgs.Empty); // raise Provides encapsulation (only owner can raise)
  11. 11LINQ
    Language Integrated Query - allows querying collections with SQL-like syntax: var adults = people.Where(p => p.Age >= 18) .OrderBy(p => p.Name) .Select(p => p.Name);
  12. 12Write LINQ query syntax vs method syntax
    Query syntax: var evens = from n in numbers where n % 2 == 0 select n; Method syntax: var evens = numbers.Where(n => n % 2 == 0); Both compile to same code
  13. 13Async/await
    Asynchronous programming keywords: async Task<int> FetchDataAsync() { await Task.Delay(1000); return 42; } int result = await FetchDataAsync(); Makes async code look synchronous
  14. 14Task vs Thread
    Thread: OS-level, heavyweight, direct control Task: abstraction over threads, lightweight, uses thread pool, better for async I/O Task is preferred in modern C#
  15. 15Lambda expressions in C#
    Anonymous functions with concise syntax: (x, y) => x + y x => x * x () => Console.WriteLine("Hello") Used with delegates, LINQ, events
  16. 16Null coalescing operator ??
    Returns first non-null value: string name = input ?? "default"; ?? = operator (C# 8+): name ??= "default"; // assign only if null
  17. 17Null conditional operator ?.
    Safely access members of nullable objects: int? length = person?.Name?.Length; Returns null if any part is null, avoiding NullReferenceException
  18. 18Extension methods
    Add methods to existing types without modifying them: public static class StringExtensions { public static bool IsNullOrEmpty(this string str) { return string.IsNullOrEmpty(str); } } str.IsNullOrEmpty();
  19. 19Using statement for
    1) Import namespaces: using System; 2) Dispose resources automatically: using (var file = File.Open("file.txt")) { // use file } // automatically disposed C# 8+: using var file = File.Open("file.txt");
  20. 20Generics in C#
    Type parameters for reusable code: List<int> numbers = new List<int>(); Dictionary<string, int> dict = new(); Custom generic: public class Box<T> { public T Value { get; set; } }
  21. 21Generic constraints
    Restrict type parameters: public class MyClass<T> where T : class // reference type public class MyClass<T> where T : struct // value type public class MyClass<T> where T : new() // has constructor public class MyClass<T> where T : IDisposable // implements interface
  22. 22abstract vs virtual
    abstract: no implementation, must be overridden in derived class, class must be abstract virtual: has implementation, can be overridden in derived class (use override keyword)
  23. 23Interface in C#
    Contract defining members without implementation: interface IAnimal { void MakeSound(); string Name { get; set; } } C# 8+: can have default implementations
  24. 24Can C# have multiple inheritance?
    No multiple class inheritance (to avoid diamond problem) Yes multiple interface implementation: class Dog : Animal, IAnimal, IComparable { }
  25. 25Access modifiers in C#
    public: accessible everywhere private: only within class (default for members) protected: class and derived classes internal: within same assembly protected internal: protected OR internal private protected: protected AND internal
  26. 26Sealed keyword
    Prevents inheritance or overriding: sealed class FinalClass { } // cannot inherit sealed override void Method() { } // cannot override further
  27. 27Params keyword
    Allows variable number of arguments: public void Print(params int[] numbers) { } Print(1, 2, 3); Print(1, 2, 3, 4, 5); Print(new[] {1, 2, 3});
  28. 28Nullable types
    Value types that can be null: int? number = null; bool? flag = null; Check: if (number.HasValue) { int n = number.Value; } Or: int n = number ?? 0;
  29. 29Tuples in C#
    Group multiple values: (int, string) person = (25, "John"); var point = (X: 10, Y: 20); Access: person.Item1, person.Item2 Or: point.X, point.Y Return multiple values from methods
  30. 30Pattern matching (C# 7+)
    switch (obj) { case int i when i > 0: Console.WriteLine($"Positive: {i}"); break; case string s: Console.WriteLine($"String: {s}"); break; case null: Console.WriteLine("Null"); break; }

And 69 more cards. Study the whole deck free

Articles about this deck

More Programming decks

See all
Study all 99 cards free