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
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
Download Logo

.NET assemblies

Assembly Overview Assembly is unit of deployment like EXE or a DLL When you create a code and build the solution, then the .NET Framework convert your code into Intermediate Language and that is placed inside the assembly(dll), which you can find inside bin folder Assembly: A compiled code library in .NET that contains types, resources, and metadata. Types of Assemblies: Executable (EXE) and Library (DLL). Components: Manifest, metadata, IL code, and resources. ...

August 3, 2024 · 1 min · 89 words · PrashantUnity
Download Logo

Abstract class Q&A

Abstract Class Interview Questions Can an abstract class have non-abstract methods? Yes, see the example below Method hiding principle (use of New keyword) 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 public abstract class Animal { public abstract void MakeSound(); public void Eat() { Console.WriteLine("Eating..."); } public void IsAlive() { Console.WriteLine("Yes"); } public virtual void Sleep() { Console.WriteLine("Sleeping..."); } } public class Dog : Animal { public override void MakeSound() { Console.WriteLine("The dog barks."); } public void Bark() { Console.WriteLine("Barking..."); } public new void IsAlive() { Console.WriteLine("NO"); } public override void Sleep() { Console.WriteLine("The dog barks Sleeping."); } } class Program { static void Main(string[] args) { // Create an instance of the Dog class Dog myDog = new Dog(); // Call methods from the abstract class (Animal) myDog.Eat(); // Output: Eating... myDog.Sleep(); // Output: The dog barks Sleeping. } }

August 3, 2024 · 1 min · 182 words · PrashantUnity