Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

variables-types

Variables and types

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Variables and types: the syntax, APIs, and habits you need before advancing in ASP.NET.

Teams ship Variables and types on every ASP.NET codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Variables and types in contexts like: Line-of-business APIs, intranets, BFF layers, and cloud-hosted services on Linux or Windows.

Write C# (top-level or Program class), click Run on server—the dev runner uses dotnet build/run on a temp net8 project (requires .NET SDK; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

C# is statically typed. Web apps use value types (int, bool, DateTime), reference types (string, classes), and generics (List<Product>) everywhere—from route IDs to JSON payloads.

Common types in ASP.NET

  • int, long — primary keys, counts, pagination
  • string / string? — names, slugs, optional query params
  • DateTime / DateTimeOffset — timestamps (prefer UTC in APIs)
  • decimal — money (avoid float for currency)
  • Guid — opaque IDs in distributed systems

var and target-typed new

var users = new List<User>();
User dto = new() { Name = "Ada" };

var is compile-time inferred—not dynamic. Use when the type is obvious from the right-hand side.

Important interview questions and answers

  1. Q: Value type vs reference type?
    A: Value types copy on assignment (stack or inline); reference types share heap objects—mutations visible through all references.
  2. Q: string? in nullable context?
    A: Compiler warns if you dereference without null check—reduces NullReferenceException in production.

Self-check

  1. Which type is safer for prices: decimal or double?
  2. Does var mean dynamic typing?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • string vs String?
  • decimal for money?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump