c# Flashcards

(22 cards)

1
Q

Proprietăți (Auto-implemented properties):

A

public string Name { get; set; } // Sintaxa clasică de proprietate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Delegates (Semnătura metodelor):

A

public delegate void MyDelegate(string message); // Definește un tip de referință către o metodă

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Evenimente (Events):

A

public event EventHandler MyEvent; // Declarare
MyEvent?.Invoke(this, EventArgs.Empty); // Lansare (fire)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Expresii Lambda:

A

(x, y) => x + y; // Metodă anonimă scurtă
books.Find(b => b.Id == 1); // Utilizare în metode de căutare

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. LINQ (Language Integrated Query)

Sintaxa de metodă (cea mai folosită):

A

var result = list.Where(x => x.Pret > 10)
.OrderBy(x => x.Nume)
.ThenByDescending(x => x.Data)
.Select(x => new { x.Nume, x.Pret }) // Proiecție anonimă
.ToList(); // Execuție imediată

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. LINQ (Language Integrated Query)

Sintaxa de interogare (Query Syntax):

A

var result = from b in books
where b.Price > 10
orderby b.Title
select b;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. LINQ (Language Integrated Query)

Operatori cheie:

A

.SelectMany(), .Distinct(), .Union(), .Intersect(), .FirstOrDefault(), .SingleOrDefault().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Entity Framework Core (DbContext & Entități)

Definire DbContext:

A

public class MyContext : DbContext {
public DbSet<Book> Books { get; set; } // Tabelă
protected override void OnConfiguring(DbContextOptionsBuilder options) {
options.UseSqlServer("ConnectionString"); // Configurare conexiune
}
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity<Book>().HasKey(b => b.ISBN); // Fluent API
}
}</Book></Book>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Entity Framework Core (DbContext & Entități)

Adnotări (Data Annotations):

A

[Key] public int Id { get; set; }
[Required, StringLength(100)] public string Title { get; set; }
[ForeignKey(“AuthorId”)] public Author Author { get; set; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Razor Pages - Logică C# (PageModel)

Handlers (Metode de răspuns):

A

[BindProperty] public Book Book { get; set; } // Legare automată la formular

public async Task<IActionResult> OnGetAsync(int? id) { // Citire
if (id == null) return NotFound();
Book = await _context.Book.FirstOrDefaultAsync(m => m.ID == id);
return Page();
}</IActionResult>

public async Task<IActionResult> OnPostAsync() { // Salvare
if (!ModelState.IsValid) return Page();
_context.Book.Add(Book);
await _context.SaveChangesAsync();
return RedirectToPage("./Index");
}</IActionResult>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Programare Asincronă (Async/Await)

Definire metodă:

A

public async Task<int> GetDataAsync() {
var data = await service.CallApi(); // Așteptare fără blocare
return data.Count;
}</int>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. .NET MAUI & SQLite (Sintaxa de mobil)

Configurare SQLite (Singleton/Lazy):

A

async Task Init() {
if (Database is not null) return;
Database = new SQLiteAsyncConnection(Constants.DatabasePath, Constants.Flags);
await Database.CreateTableAsync<TodoItem>();
}</TodoItem>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. .NET MAUI & SQLite (Sintaxa de mobil)
    Operații SQLite:
A

await Database.InsertAsync(item);
await Database.Table<TodoItem>().ToListAsync();
await Database.DeleteAsync(item);</TodoItem>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. .NET MAUI & SQLite (Sintaxa de mobil)

HttpClient & JSON (REST):

A

HttpClient client = new HttpClient();
var response = await client.GetAsync(“https://api.com/items”);
if (response.IsSuccessStatusCode) {
string content = await response.Content.ReadAsStringAsync();
var items = JsonSerializer.Deserialize<List<Item>>(content);
}</Item>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. Configurare (Program.cs)

Dependency Injection:

A

builder.Services.AddScoped<IMyService, MyService>(); // Transient, Scoped, Singleton

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. Configurare (Program.cs)

Middleware Pipeline:

A

app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

17
Q

Cum verifici dacă o listă e goală în LINQ?

A

if (!list.Any())

18
Q

Cum transformi un string în int în C#?

A

int.Parse(s) sau int.TryParse(s, out var result)

19
Q

Cum forțezi EF Core să ignore o proprietate?

A

[NotMapped] deasupra proprietății.

20
Q

Cum obții ID-ul utilizatorului logat?

A

User.FindFirst(ClaimTypes.NameIdentifier)?.Value

21
Q

Cum navighezi la o pagină cu parametri în MAUI?

A

await Shell.Current.GoToAsync($”{nameof(DetailsPage)}?id={item.ID}”);