Download Logo

Loops (Ch. 7)

Understanding Loops in C# Loops are fundamental programming constructs that allow you to execute a block of code repeatedly. They’re essential for: Processing collections of data Repeating operations until a condition is met Automating repetitive tasks Iterating through arrays and lists Think of loops as a way to tell the computer: “Do this task over and over again until I tell you to stop.” Types of Loops in C# C# provides four main types of loops: ...

June 19, 2024 · 15 min · 3098 words · PrashantUnity
Download Logo

Methods in C# (Ch. 8)

Understanding C# Methods and Functions What are Functions and Methods? A function (also called a method in C#) is a reusable block of code that performs a specific task. Think of it as a recipe that you can follow multiple times with different ingredients (parameters) to get the same type of result. Why Use Functions? Functions solve several important problems in programming: Code Reusability: Write once, use many times Code Organization: Break complex problems into smaller, manageable pieces Maintainability: Fix bugs or update logic in one place Testing: Test individual pieces of functionality Readability: Make code more self-documenting Real-World Example: The Problem Without Functions Let’s say you want to calculate the sum of two numbers with validation. Without functions, you’d write: ...

June 20, 2024 · 13 min · 2611 words · PrashantUnity
Download Logo

Linear structures (Ch. 9)

C# Linear Data Structures Arrays Arrays are fixed-size collections of elements of the same type. They allow direct access to elements via index. Example: Arrays 1 int[] numbers = new int[] { 1, 2, 3, 4, 5 }; Lists Lists are dynamic arrays that can grow in size. They provide methods to add, remove, and access elements. Example: Lists 1 2 3 List<string> names = new List<string>(); names.Add("Alice"); names.Add("Bob"); Queues Queues follow the First-In-First-Out (FIFO) principle. Elements are added at the end and removed from the front. ...

June 20, 2024 · 2 min · 375 words · PrashantUnity
Download Logo

JSON to tree in C#

Handling Dynamic JSON with Variable Property Names Here is one way you can solve it 😁. Since json can have name and Several children so we can create Tree like node 1 2 3 4 5 public class JsonNode { public string Name {get;set;} public List<JsonNode> Child {get;set;} = []; } Below code generate tree using Recursion 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 using System; using System.Collections.Generic; using System.Text.Json; public static JsonNode BuildTree(JsonElement element, string nodeName) { var node = new JsonNode { Name = nodeName }; if (element.ValueKind == JsonValueKind.Object) { foreach (var property in element.EnumerateObject()) { node.Child.Add(BuildTree(property.Value, property.Name)); } } else if (element.ValueKind == JsonValueKind.Array) { int index = 0; foreach (var item in element.EnumerateArray()) { node.Child.Add(BuildTree(item, $"[{index}]") ); index++; } } else { node.Child.Add(new JsonNode { Name = element.ToString() }); } return node; } Here we we have sample code to initialize/ use the above code ...

February 24, 2025 · 2 min · 240 words · PrashantUnity
Download Logo

Learn C# — links

C# Learning Resources for Beginners Welcome to this comprehensive guide of C# programming resources! Whether you’re interested in game development, web applications, or general software development, these carefully curated resources will help you start your C# journey. This guide is organized by topic, from basic setup to advanced concepts, making it easy to find exactly what you need at each stage of your learning process. Official Documentation Start your C# journey with Microsoft’s official documentation - the authoritative source for everything C#. The documentation includes: ...

October 19, 2025 · 4 min · 685 words · PrashantUnity
Download Logo

Classes in C# (Ch. 11)

Class A class represents a blueprint of an object. Currently, we know some basic data types: For representing numbers, we use types like int, long, byte, decimal, etc. For representing words, we use string or arrays of characters (char[]). For storing collections of numbers, we use arrays (int[], float[], etc.). However, what about storing complex objects like Person, Planet, etc.? For example, a Person object might have properties like Name (a string), Age (an integer), and methods like IsCoding(). classDiagram class Person{ +Name +Age +IsCoding() } From the diagram above, we see that a class named Person encapsulates a contextual representation driven by developers. It defines properties and behaviors specific to a person, allowing us to model and work with such complex entities in code. ...

June 24, 2024 · 6 min · 1173 words · PrashantUnity
Google Sheets Integration

Sheets CRUD service

Overview The GenericGoogleSheetsService is a powerful .NET service that provides a complete CRUD (Create, Read, Update, Delete) interface for Google Sheets integration. This service eliminates the need to write boilerplate code for each entity type by using generic programming and reflection to automatically map between your C# objects and Google Sheets rows. Link to GitHub Repository: GenericGoogleSheetsService on GitHub Key Features Generic Type Support: Works with any class that implements IEntityWithId and has a parameterless constructor Automatic Type Mapping: Uses reflection to map property names to Google Sheets columns Complete CRUD Operations: Create, Read, Update, and Delete operations with async support Flexible Authentication: Supports both JSON credentials and service account file paths List Property Support: Handles List<string> properties with custom delimiters Error Handling: Graceful error handling with detailed logging Multiple Sheet Support: Can work with different sheets within the same spreadsheet Use Cases Data Synchronization: Keep your application data synchronized with Google Sheets Reporting: Export application data to Google Sheets for analysis Configuration Management: Store application configuration in Google Sheets Data Backup: Use Google Sheets as a backup storage solution Collaborative Data Entry: Allow multiple users to edit data through Google Sheets Prerequisites Before implementing this service, ensure you have: ...

Download Logo

Lists to Excel

Creating Excel File from List With Different Sheet With Naming nuget package used OpenXML 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 public static MemoryStream WriteMultipleListsToExcel_OpenXml(params (string sheetName, IEnumerable<object> list)[] sections) { var memoryStream = new MemoryStream(); using (var spreadsheetDocument = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook)) { var workbookPart = spreadsheetDocument.AddWorkbookPart(); workbookPart.Workbook = new Workbook(); var workbookProps = new WorkbookProperties() { DefaultThemeVersion = 124226 }; // Ensure workbook properties workbookPart.Workbook.AppendChild(workbookProps); var sheets = workbookPart.Workbook.AppendChild(new Sheets()); uint sheetId = 1; foreach (var (sheetName, list) in sections) { var worksheetPart = workbookPart.AddNewPart<WorksheetPart>(); worksheetPart.Worksheet = new Worksheet(new SheetData()); var sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = sheetId++, Name = sheetName }; sheets.Append(sheet); var sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>(); var type = list.GetType().GetGenericArguments()[0]; var properties = type.GetProperties(); // Add header row var headerRow = new Row(); foreach (var prop in properties) { headerRow.Append(CreateTextCell(prop.Name)); } sheetData.Append(headerRow); // Add data rows foreach (var item in list) { var dataRow = new Row(); foreach (var prop in properties) { var value = prop.GetValue(item)?.ToString() ?? string.Empty; dataRow.Append(CreateTextCell(value)); } sheetData.Append(dataRow); } worksheetPart.Worksheet.Save(); } workbookPart.Workbook.Save(); } memoryStream.Position = 0; return memoryStream; } private static Cell CreateTextCell(string value) { return new Cell { CellValue = new CellValue(value), DataType = CellValues.String }; } Use of Above Function lets Suppose we have Below Class ...

Download Logo

Tables in Polyglot

Setup Polyglot Notebook Environment Import nuget package 1 #r "nuget: Microsoft.Data.Analysis" Import namespace 1 2 3 using System; using System.Collections.Generic; using Microsoft.Data.Analysis; Create class 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public class RedirectEntry { public string WebsiteUrl { get; set; } public string RedirectUrl { get; set; } public string Status => IsValid ? "✅" : "❌"; public bool IsValid { get; set; } } var data = new List<RedirectEntry> { new RedirectEntry { WebsiteUrl = "https://codefrydev.in/Updates", RedirectUrl = "https://codefrydev.in/", IsValid = true }, }; Create Generic Function for any type of list injection 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 DataFrame ShowTable<T>(List<T> items) { var properties = typeof(T).GetProperties(); List<DataFrameColumn> columns = new(); foreach (string header in properties.Select(p => p.Name)) { columns.Add(new StringDataFrameColumn(header, new List<string>())); // Read as string } foreach(var item in items) { for (int i = 0; i < properties.Length; i++) { var values = properties.Select(p => p.GetValue(item)?.ToString() ?? "").ToList(); ((StringDataFrameColumn)columns[i]).Append(values[i]); } } return new DataFrame(columns); } Simply call the function in next cell without any commas or stuff 1 ShowTable(data)

Download Logo

Firestore CRUD

Overview Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform. It is a NoSQL document database that lets you easily store, sync, and query data for your applications at a global scale. In this guide, we’ll walk through how to implement a complete CRUD (Create, Read, Update, Delete) solution for Firestore in .NET with built-in schema validation and type conversion support. ...

November 15, 2025 · 17 min · 3471 words · PrashantUnity