SkillPilotAI

Interview prep

The last video turns the course into interview answers: C# output puzzles you should be able to solve in seconds, the most-asked ASP.NET Core and EF Core questions with short answers, and a three-step formula for answering any question.

75.1 Puzzle 1: struct vs class copy

  • Money is a struct, Wallet is a class; both start at 100 and a copy is set to 500.
  • Many people say 500 for both; the real output is 100 and 500.
C#
var m1 = new Money { Amount = 100 };var m2 = m1;m2.Amount = 500; var w1 = new Wallet { Balance = 100 };var w2 = w1;w2.Balance = 500; Console.WriteLine(m1.Amount);Console.WriteLine(w1.Balance); struct Money { public int Amount; }class Wallet { public int Balance; }
Output
100500
Why 100 and 500?
  1. 1.var m2 = m1 (struct Money): the whole value is copied

  2. 2.m2.Amount = 500 changes only the copy; m1 stays 100

  3. 3.var w2 = w1 (class Wallet): only the reference is copied

  4. 4.w1 and w2 point to the same object on the heap

  5. 5.w2.Balance = 500 is visible through w1 -> 500

Value type: copy. Reference type: shared object (video 5)

75.2 Puzzle 2: async print order

  • PayAsync() is called without await on the second line.
  • An async method runs synchronously until the first await on an incomplete Task, then returns control to the caller.
  • So B prints right after A, C prints while the delay runs, D after the delay, then E: A B C D E.
C#
Console.WriteLine("A");Task task = PayAsync();Console.WriteLine("C");await task;Console.WriteLine("E"); async Task PayAsync(){    Console.WriteLine("B");    await Task.Delay(100);    Console.WriteLine("D");}
Output
ABCDE
How A B C D E happens
  1. 1.Caller prints A and calls PayAsync()

  2. 2.PayAsync prints B synchronously

  3. 3.await Task.Delay(100) is incomplete -> control returns to caller

  4. 4.Caller prints C, then await task waits

  5. 5.Delay finishes: PayAsync prints D and completes

  6. 6.Caller resumes and prints E

75.3 Checkpoint: deferred execution

  • Where only builds the query; it runs when Count() enumerates the list.
  • By then the list has 100, 200, 300, 400, and three are above 150: output 3 (video 32).
C#
var prices = new List<int> { 100, 200 };var costly = prices.Where(p => p > 150); prices.Add(300);prices.Add(400); Console.WriteLine(costly.Count());
Output
3

75.4 ASP.NET Core: most-asked

QuestionShort answer
DI lifetimesTransient: new object every time. Scoped: one per request. Singleton: one for the whole app. Injecting scoped into singleton = captive dependency bug.
Middleware vs filtersMiddleware runs in the pipeline on every request; filters run around the action inside MVC and see action arguments and result.
JWT vs cookiesHttpOnly cookie for browser apps; JWT bearer token for mobile or service clients.
Minimal APIs vs controllersBoth fully supported; Minimal APIs suit small focused APIs, controllers are common in large structured projects.

75.5 EF Core: IEnumerable vs IQueryable

  • With IEnumerable<Order>, Where runs in memory: the SQL has no WHERE and the whole Orders table loads.
  • With IQueryable<Order>, Where builds an expression tree that EF Core translates into SQL WHERE.
  • Same result, but on a table with lakhs of rows the first version slows the app down.
C#
// Wrong: Whole table in memoryIEnumerable<Order> orders = db.Orders;var big = orders    .Where(o => o.Total > 1000)    .ToList(); // SQL (EF Core log):// SELECT "o"."Id", "o"."Total"// FROM "Orders" AS "o"
C#
// Right: Filter runs in the databaseIQueryable<Order> orders = db.Orders;var big = orders    .Where(o => o.Total > 1000)    .ToList(); // SQL (EF Core log):// SELECT "o"."Id", "o"."Total"// FROM "Orders" AS "o"// WHERE "o"."Total" > 1000
PointIEnumerable<T>IQueryable<T>
Where runsIn memory (LINQ to Objects)In the database (translated to SQL)
Filter takesFunc<T,bool> delegateExpression tree
Data loadedWhole tableOnly matching rows

75.6 EF Core: most-asked

  • N+1: one query loads a list, then one query per row. Fix with Include or a Select projection.
  • Detect it with SQL logging or ToQueryString().
  • Tracking: DbContext tracks loaded entities so SaveChanges can detect changes; use AsNoTracking for read-only queries.
  • Concurrency: mention an optimistic concurrency token (like Stock in the capstone).

75.7 How to answer: the 3-step formula

  1. Definition in one line: IQueryable keeps the query as an expression tree that the provider translates into SQL.
  2. Example or code: the orders filter runs in the database's WHERE.
  3. Gotcha or trade-off: a filter after an IEnumerable variable runs in memory.
Answer structure
  1. 1.Hear the question

  2. 2.One-line definition

  3. 3.Small example or code

  4. 4.Gotcha or trade-off

  5. 5.Short answer that shows depth and survives the follow-up

75.8 Common mistakes

  • Treating the interview as memorising syntax and definitions: interviewers check trade-offs (scoped vs singleton, Dapper vs EF Core).
  • Memorised answers get caught on the first follow-up question.
  • Bluffing: if you don't know, say so and explain how you would approach it; that is a strong answer too.
  • Filtering after assigning a DbSet to an IEnumerable variable.

75.9 Preparation best practices

  1. Revise the interview scene of every video in the course: that is your revision list.
  2. Run small programs like these puzzles with dotnet run, and guess the output first.
  3. Put the capstone on GitHub and add the link to your resume.
  4. Do a mock interview with a friend and explain things out loud.

75.10 Interview tips

  • Struct copy copies the value, class copy copies the reference.
  • An async method runs synchronously until the first await; LINQ Where runs only when enumerated.
  • Keep short answers ready for DI lifetimes, middleware vs filters, JWT vs cookies.
  • In EF Core remember IQueryable, Include and AsNoTracking.
  • Answer every question as definition, example, gotcha.