Skip to main content

Posts

AI-Powered PR Review with Azure DevOps and OpenAI

Recent posts

Functions and Methods

Functions and Methods in C# 🚀 Functions (or methods ) in C# encapsulate logic and allow code reuse . They take input parameters , process logic, and return results . 1️⃣ Defining and Calling Methods A method in C# consists of: Access modifier Return type Method name Parameters (optional) Method body 🔹 Basic Method Syntax: [AccessModifier] ReturnType MethodName(ParameterList) { // Method body return value; // (if applicable) } Example: class Program { static void SayHello() // No parameters, no return type { Console.WriteLine("Hello, World!"); } static void Main() { SayHello(); // Method call } } 2️⃣ Methods with Parameters 🔹 Passing Arguments Parameters allow input values to be passed to a method. static void Greet(string name) { Console.WriteLine($"Hello, {name}!"); } static void Main...

Control Structures if-else, switch, loops (for, while, do-while)

Control Structures in C# 🚀 Control structures help control the flow of execution in a program. C# provides conditional statements ( if-else , switch ) and loops ( for , while , do-while ) to handle different scenarios. 1️⃣ Conditional Statements 🔹 if-else Statement The if-else statement executes code based on conditions . Syntax: if (condition) { // Code runs if condition is true } else if (anotherCondition) { // Code runs if anotherCondition is true } else { // Code runs if none of the above conditions are true } Example: int age = 20; if (age >= 18) { Console.WriteLine("You are an adult."); } else { Console.WriteLine("You are a minor."); } ✅ Nested if-else int number = 10; if (number > 0) { if (number % 2 == 0) { Console.WriteLine("Positive Even Number"); } else { Console.WriteLine("Positive Odd Number"); } } 🔹 switch Statement The switch statemen...

Variables, Data Types, and Operators

Variables, Data Types, and Operators in C# 🚀 Understanding variables, data types, and operators is essential for writing C# programs. Let’s go step by step. 1️⃣ Variables in C# A variable is a named storage location that holds data. 🔹 Declaring Variables dataType variableName = value; Example: int age = 30; string name = "John"; double price = 99.99; 🔹 Variable Naming Rules ✅ Must start with a letter or underscore ( _ ) ✅ Can contain letters, digits, and underscores ✅ Case-sensitive ( myVar and MyVar are different) ✅ Cannot use C# keywords (e.g., int , class , public ) 2️⃣ Data Types in C# C# has value types (stored directly in memory) and reference types (stored as references). 🔹 Common Value Types Data Type Size Example Description int 4 bytes int x = 100; Stores whole numbers double 8 bytes double pi = 3.14; Stores decimal numbers float 4 bytes float price = 9.99f; Smaller decimal precision char 2 bytes char grade...

Setting up the environment

Setting Up Your C# Development Environment 🚀 Setting Up Your C# Development Environment If you’re ready to dive into C# and .NET development , the first step is setting up a proper environment. This includes installing the .NET SDK , choosing an IDE , and configuring essential tools. 1️⃣ Install the .NET SDK The .NET SDK provides everything you need to build, run, and publish .NET applications. ✅ Download & Install .NET SDK Visit the official .NET download page: https://dotnet.microsoft.com/download Download the latest .NET SDK (LTS version recommended). Run the installer and follow the instructions. ✅ Verify Installation dotnet --version If installed correctly, you’ll see the installed .NET version . 2️⃣ Choose an IDE (Integrated Development Environment) You need an IDE or code editor to write ...

Passing Data from Controller to View in ASP.NET Core MVC

Passing Data from Controller to View in ASP.NET Core MVC In ASP.NET Core MVC, passing data from the controller to the view is a crucial part of rendering dynamic content. There are several ways to pass data, including ViewData , ViewBag , and Model . Let's explore these methods: 1. Passing Data Using Model The most common and recommended way to pass data from the controller to the view is by using a model . Steps: Create a Model : Define a class that will hold the data. Pass the Model : Use the View() method in the controller to pass the model data to the view. Use the Model in the View : In the view, specify the model type and access its properties. Example: Step 1: Create a Model public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } } Step 2: Controller public class ProductController : Controller { public IActionResult Index() { var product = new Product ...

Creating Controllers and Actions in ASP.NET Core MVC

Creating Controllers & Actions in ASP.NET Core MVC In ASP.NET Core MVC, Controllers are responsible for handling incoming HTTP requests and returning an appropriate response. Actions are methods within controllers that handle specific requests and provide the logic for what should happen when those requests are made. 1. Understanding Controllers Controllers are classes in ASP.NET Core that contain action methods . Each action method corresponds to a route in the application and performs a specific task, such as displaying a view or handling user input. Syntax : public class ControllerNameController : Controller { // Action methods go here } A controller class typically ends with "Controller", e.g., ProductController , HomeController . The Controller class inherits from the base class Controller provided by ASP.NET Core. 2. Creating a Basic Controller Let’s create a controller to handle product-related actions in a simple e-commerce applicat...