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, paginationstring/string?— names, slugs, optional query paramsDateTime/DateTimeOffset— timestamps (prefer UTC in APIs)decimal— money (avoidfloatfor 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
- 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. - Q: string? in nullable context?
A: Compiler warns if you dereference without null check—reduces NullReferenceException in production.
Self-check
- Which type is safer for prices:
decimalordouble? - Does
varmean dynamic typing?