Frequently Asked Questions About Shiva Gautam C# .NET Foundation Builder

22 answers covering everything from basics to advanced usage.

// Basics

What is .NET Core Framework and how is it different from classic .NET?

.NET Core Framework is the open-source, cross-platform version of .NET that runs on Windows, macOS, and Linux without requiring a license. It is the actively updated framework as of 2025, with .NET 9.0 being the latest. Classic .NET Framework was Windows-only; .NET Core (now just '.NET') is the modern default for new projects.

Is C# a fully object-oriented language?

C# is described as a fully object-oriented language, but it is not 100% pure OOP because it supports primitive data types (int, float, char) inherited from C/C++. In pure OOP, everything would be an object. C# balances OOP structure with practical primitive types, while still deriving all types ultimately from the Object root class.

What are the minimum system requirements to install Visual Studio 2022?

You need Windows 10 or 11, at least 4GB RAM, 20-25GB of free disk space, and an i3 processor minimum (i5 or i7 preferred). Visual Studio 2022 Community Edition is free. Ensure you download the full Visual Studio IDE, not Visual Studio Code, which is a separate lightweight editor.

What is the difference between a variable, a constant, and a literal in C#?

A variable holds data that can change and is declared with a data type and identifier (int a = 10). A constant uses the 'const' keyword and cannot be reassigned after declaration (reassignment causes a compile-time error). A literal is the actual value assigned — 'Hello' is a string literal, 10 an integer literal, 12.34 a float literal, and true a boolean literal.

What does 'internal' mean and when do I use it over public?

internal makes a class member accessible across all classes within the same project but not from outside projects. Use internal for most methods in a single-project learning setup — it's broader than private (same class only) but safer than public. Use public only when a member genuinely needs to be reachable from other projects or external assemblies.

// How To

How do I create a new class in Visual Studio for a task?

Right-click your project in Solution Explorer, choose Add > New Item > Class, and give it a meaningful name. Set the access modifier to 'internal' (same project) or 'public' (cross-project). Add one method per task inside it. Never create a new project for each session — one project supports unlimited classes.

How do I build a calculator using the method-per-task pattern?

Create one class named 'Calculator' with four internal methods: Add(), Subtract(), Multiply(), Divide(). Declare global variables a and b, and a separate Accept() method using Console.ReadLine() with Convert.ToInt32() for input. In Program.cs Main, create an object (Calculator obj = new Calculator()), call obj.Accept() first, then call the specific operation. Never put all four operations directly in Main.

How do I swap two numbers using a third variable in C#?

Use three variables — a = 5, b = 10, and temp. Assign temp = a to back up a, then a = b to overwrite a, then b = temp to restore the original a into b. Think of two water bottles (hot and cold) needing a third empty bottle to swap contents. Place this in a method 'void Swap()' inside a class and call it from Main via an object.

How do I set the PATH to compile C# from the command prompt?

Set the PATH environment variable to the .NET framework directory, typically C:\Windows\Microsoft.NET\Framework\v4.x, where the csc compiler lives. Then navigate to your .cs file's folder in Command Prompt and run 'csc filename.cs'. This compiles your source into CIL and produces a .exe you can execute directly.

When should I move from Notepad compilation to Visual Studio?

Do the Notepad and command-prompt compilation exercise for exactly one program to reveal the CIL → CLR → OS pipeline, then move to Visual Studio permanently. The manual exercise builds understanding of what happens behind the scenes; Visual Studio then handles building, debugging, and execution efficiently so you can focus on learning C# concepts rather than tooling.

What practice programs should I complete to solidify C# fundamentals?

Complete these after each concept: a Simple Interest calculator, a Compound Interest calculator, Area of Circle and Triangle, a Feet-to-Inches and Inches-to-Feet converter, reversing a three-digit number, and swapping two numbers using a third variable. Implement each with the method-per-task pattern, then review your solutions before moving to the next topic.

// Troubleshooting

Why does my C# program say the method is inaccessible?

Methods default to private, so they cannot be called from outside their class. Set the access modifier explicitly to internal (same project) or public (cross-project). If Visual Studio greys out a method in IntelliSense, it is private. Also confirm you are not trying to call an instance method without first creating an object with 'new'.

Why do I get an error assigning Console.ReadLine() to an int?

Console.ReadLine() always returns a string, so assigning it directly to an int fails. Wrap it in a Convert call: int a = Convert.ToInt32(Console.ReadLine()) for integers, or Convert.ToDouble() for doubles. The Convert class is the standard C# tool for matching input to your target variable's type.

Why can't I call my static method through an object?

Static methods are always called via the class name — ClassName.MethodName() — because their memory is allocated at compile time and they don't belong to any instance. Calling a static method through an object is incorrect. Conversely, non-static (instance) methods always require an object created with 'new' and cannot be called via the class name.

Why does my const variable throw a compile-time error?

Constants declared with the 'const' keyword cannot be reassigned after their initial declaration. If you try to give a const a new value later in your code, the compiler rejects it at compile time. If you need a value that changes, use a normal variable instead of a constant.

// Comparisons

How does using object compare to using var for unknown data types?

Use object when you need a typed container for data whose type is unknown at design time — object is the root class of all .NET types and is type-safe as a reference container supporting boxing/unboxing. var is untyped and not type-safe; it infers its type at compile time but should not be treated as a safe universal container. Prefer object for genuine type uncertainty.

What is the difference between primitive and derived data types in C#?

Primitive types are inherited from C/C++ and written lowercase — int, float, char, double, bool, string. Derived (reference) types are defined under .NET and written with capitals — Int16, Int32, Int64, String, Object, and custom classes. All derived types trace back to the Object root class. String uniquely exists as both primitive (lowercase) and derived (capital S).

How does Console Application compare to Windows Forms or web apps for learning?

A Console Application is the best starting point because all input and output happens via a simple console screen, letting you master language fundamentals without GUI or web complexity. Windows Forms and WPF add desktop UI concerns; ASP.NET Core MVC adds web architecture; MAUI targets mobile. Learn C# fundamentals in a console app first, then branch into your target application type.

// Advanced

How does the CIL to CLR to OS pipeline actually work?

When you compile C#, the csc compiler produces Common Intermediate Language (CIL) — platform-neutral code, not binary. The Common Language Runtime (CLR) then converts that CIL into binary at runtime and hands it to the Operating System for execution. This two-stage design is why .NET can support many languages and run cross-platform under .NET Core.

When should I use protected and protected internal access modifiers?

Use protected when a class member should be accessible only within its own class and derived (inheriting) subclasses. Use protected internal to allow access within the same project OR from derived classes in other projects. For most foundational programs, internal (same project) and public (cross-project) cover your needs; reach for protected once you begin working with inheritance.

Why should I keep Program.cs Main only for calling methods?

Keeping Main as a caller enforces separation of concerns — logic lives in dedicated, well-named classes and methods, making it reusable, inheritable, and maintainable. If you cram arithmetic and input handling into Main, you lose the ability to call specific functionality on demand and your program becomes hard to test and extend. Main should orchestrate; classes should implement.

What is the Web API's role in modern .NET application architecture?

A Web API acts as the communicator or data carrier between the front-end (React, Angular) and the database layer. Built with .NET, it exposes endpoints that transfer data between UI and storage. In modern architecture, the front-end never talks to the database directly — the Web API mediates all data exchange, which is why it's central to full-stack .NET applications.