Skip to main content

Posts

Showing posts with the label C#

AI-Powered PR Review with Azure DevOps and OpenAI

AI-Powered PR Review with Azure DevOps Overview: This guide shows you how to set up an automated AI-powered Pull Request review system using Azure OpenAI and Azure DevOps. The AI will automatically detect security vulnerabilities, performance issues, and code quality problems in your pull requests. Prerequisites Create Azure OpenAI Sign in to Azure Portal Go to https://portal.azure.com Sign in with your Azure account Create Resource Click "Create a resource" (top left) Search for "Azure OpenAI" Click "Azure OpenAI" → "Create" Create a Deployment Model Access Azure AI Foundry Portal Go to https://ai.azure.com OR from Azure Portal → Your OpenAI resource → "Explore Azure AI Foundry portal" Create/Select Project Create new project: AI-PR-Review Select your Azure OpenAI resource Navigate to Deployments Left sidebar → "Deployments...

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 ...

Console app: Building a Library Management System in C#

Introduction In this blog post, I will guide you through creating a simple Library Management System in C# that utilizes the concepts of encapsulation, polymorphism, and inheritance. This exercise is perfect for practicing object-oriented programming principles. Objective Create a simple Library Management System that demonstrates encapsulation, polymorphism, and inheritance. Requirements 1. Encapsulation    Create a `Book` class with private properties: `Title`, `Author`, `ISBN`, and `IsAvailable`.    Provide public methods to get and set these properties as needed. 2. Inheritance    Create a base class `LibraryItem` with common properties such as `ID`, `Title`, and `IsAvailable`.    The `Book` class should inherit from `LibraryItem`.    Create another derived class `Magazine` that inherits from `LibraryItem` and has additional properties such as `IssueNumber` and `Publisher`. 3. Polymorphism Create a method `DisplayDetails` in the `Lib...

Beginner: Temperature Converter in C#

Introduction In this tutorial, we will create a simple console application in C# that converts temperatures between Celsius, Fahrenheit, and Kelvin. This is a great project for beginners to practice basic programming concepts and console input/output operations. Code Implementation: ITemperatureConverter internal interface ITemperatureConverter { TemperatureUnit ReadConvertUnit(string baseUnit); bool IsInputValid(string baseValue, TemperatureUnit baseUnit, TemperatureUnit targetUnit); decimal Process(string baseUnitValue, TemperatureUnit baseUnitEnum, TemperatureUnit targetUnitEnum); } TemperatureDataService Read user input public TemperatureUnit ReadConvertUnit(string inputUnit) { if (!int.TryParse(inputUnit, out var unit)) { Console.WriteLine("Invalid temperature unit. Please enter convert unit: "); inputUnit = Console.ReadLine(); ReadConvertUnit(inputUnit); ...

Palindrome Checker

C# Exercise: Palindrome Checker C# Exercise: Palindrome Checker Description Write a C# program that checks if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization. For example, "radar" and "A man a plan a canal Panama" are palindromes. Program.cs Console.WriteLine("Enter a text to check if it is a palindrome"); var text = Console.ReadLine(); var check = new PalindromeChecker.Class.PalindromeChecker(); if (string.IsNullOrEmpty(text)) Console.WriteLine("Text value empty"); if (check.IsPalindrome(text)) Console.WriteLine($"'{text}' is a palindrome"); else Console.Writ...
C# Exercise: Fibonacci Sequence C# Exercise: Fibonacci Sequence Description Write a C# program to generate the Fibonacci sequence up to a specified number of terms. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. For example, the first few numbers in the Fibonacci sequence are 0, 1, 1, 2, 3, 5, 8, 13, 21, ... Your program should prompt the user to enter the number of terms they want in the Fibonacci sequence and then output the sequence up to that number of terms. Exercise Console.WriteLine("Enter the number of terms for the Fibonacci sequence:"); var numTerms = Convert.ToInt32(Console.ReadLine()); var iteration = 0; var firtNumber = 0; var secondNumber = 1; var nextNumber = 0; ...

CardHolder - business card storage application

Problem      Throughout my career, I met many professionals in their respective fields and exchange a few words, and obtained their business cards as well. I used to store them in my cardholder or simply in my cupboard but it was quite frustrating to find a specific business card of someone when you need their services. moreover, there was quite some more annoying situation where I was not at home and don't have any business card at my reach but badly need to contact someone to reach out for their services so bearing in mind that modern problem requires modern solution I decided to create my own application which will solve the issue to store, search and carry all those business cards around. Solution my first solution was to download an already existing application, but some were paid application some were freemium and all of them did not have the specific feature that I want to use in my day to day basis  I started creating prototypes using two Xamarin which is a c...

Asymmetric cryptography using Angular 9 and Asp.net Web Api

Introduction Nothing better than to learn something new during our free time. A new programming language, why not. Thus to make my mind busy as a geek i tried to learn Angular 9 and create a small application nothing fancy at all and called it Asymmetric cryptography. In simple words using Angular 9 to create the client side application and hooked it up with an ASP.NET web api. To conclude i deployed the application on Microsoft azure. How it works Key generation Asymmetric cryptography uses 2 key pairs to encryption  and decryption data. The 2 keys consist of a private key and a public key. To produce a cipher text (encryption), the public key alongside with the plain text will be used. In the same way, in order to produce a plain text (decryption) the cipher text will be used with the private key. The images below illustrate how asymmetric cryptography works: To use the application first select the key length namely: 512 bit 1024 bit 2048 bit 4096 bit...