Posts

How to Initialize Struct – C# Struct Initialization Guide

Image
How to Initialize Struct – C# Struct Initialization Guide In C#, there are multiple ways to declare and initialize structs. While using just one method is often enough, it's common to encounter different initialization styles in real-world code. This guide summarizes the most common approaches, including how to handle struct arrays and lists. Struct Declaration struct Item { public string name; public int price; public string desc; } 1. Declare First, Assign Later This is the most straightforward method. Declare the struct first, then assign values to its fields one by one. Item item; item.name = "Fireball"; item.price = 100; item.desc = "Deals fire damage to the enemy."; Note: Structs are value types, so you can declare them without new . However, you must initialize all fields before use, or you'll get a compile-time error. 2. Use new and Assign Fields Item item = new Item(); item.name = "Fir...

C# Default Access Modifiers: internal or private?

What is the Default Access Modifier in C#? In C#, if you omit access modifiers when declaring class , struct , or field , the compiler applies a default. Understanding what these defaults are helps you avoid unintentional access issues in your code. Default for class and struct: internal When you declare a class or struct without specifying an access modifier, C# considers it internal by default. That means it is accessible only within the same project . // Default is internal struct MyStruct { } class MyClass { } What does “same project” mean? Each project in a solution compiles into its own .dll or .exe , known as an assembly. The internal keyword means that other projects—even in the same solution—cannot access the type. Same project : can access internal types Different project in same solution : cannot access internal types Example project structure MySolution/ ├── ProjectA ← declares internal struct └── ProjectB ← refer...

GitHub Series #5 : Understanding Clone, Commit, Push, Publish, and Pull

Git Essentials: Understanding Clone, Commit, Push, Publish, and Pull When using Git, you'll frequently come across several key terms. Becoming familiar with these will help you better understand how Git works. Below is a summary of the most commonly used commands and when to use them. Clone What it means : Copy a GitHub repository to your local computer. When to use : When you’ve created a repository on GitHub and want to start working on it locally. Example : Studying or modifying an open-source project made by someone else. Commit What it means : Save changes to your local repository (record a version). When to use : After editing or creating files and you want to record those changes. Note : A commit only saves changes to your local Git repository — not to GitHub. Push What it means : Upload your committed changes to GitHub. When to use : When you're ready to back up your work or share it with others via GitHub...

Setting Up a Basic Follow Camera with Cinemachine 3.x

Image
Setting Up a Basic Follow Camera with Cinemachine 3.x Cinemachine has been significantly upgraded in version 3.x, introducing new concepts, improved terminology, and a refined workflow. In this post, we’ll go through how to set up a simple follow camera using the latest version. For more advanced examples, be sure to check out the sample scenes provided in the Cinemachine package—they’re very helpful for understanding the system. Install the Cinemachine Package Start by downloading and importing the Cinemachine package from the Unity Package Manager. Check the Main Camera After installation, you'll notice that the Main Camera now has a Cinemachine Brain component attached. Make sure the Live Camera field shows the name of your Cinemachine Camera. Create a Cinemachine Camera In the Hierarchy window, right-click and go to Cinemachine > Cinemachine Camera to create a new virtual camera. Set the Tracking Targe...

Perfect Understanding of new() in C#

Image
Perfect Understanding of new() in C# Using new() in C# seems simple. You add new , and suddenly an object appears in memory, ready to use. But under the hood, this single line of code performs two distinct operations. First, it allocates memory. Second, it initializes the object by calling its constructor. These two actions often happen together, so we tend to see them as one. But conceptually, they are entirely different responsibilities. new Only Allocates Memory The new keyword itself is responsible for memory allocation only. For structs, memory is allocated on the stack . For classes, memory is allocated on the heap . This means new simply tells the runtime to "reserve space"—it doesn't say what to put in that space. That job belongs to something else. Initialization Happens via () The parentheses () represent a call to a constructor function, just like when calling any other method in C#. This constructo...

GitHub Series #4 : Installing GitHub Desktop and Creating a Local Repository

Image
GitHub Series #4: Installing GitHub Desktop and Creating a Local Repository Let's install GitHub Desktop, a handy tool that simplifies repository management with just a few clicks. 1. Installing GitHub Desktop Download from: https://desktop.github.com Run the installer and complete the setup with default options. Once installed, sign in with your GitHub account. 2. Two Starting Points for Repository Setup When using GitHub Desktop, your workflow will depend on where your project starts: [A] You created a repository on GitHub web → Clone [B] You started with a folder on your computer → New Repository [A] Cloning a Repository from GitHub Create a repository on GitHub via the website. Open GitHub Desktop and go to File > Clone Repository . Select the repository and choose a local path. Click Clone to download it to your PC. [B] Creating a New Repository on Local Drive ...

GitHub Series #3 : Signing Up and Creating a Repository

Image
GitHub Series #3: Signing Up and Creating a Repository To start managing your code on GitHub, you first need to sign up for an account . Visit https://github.com Signing up is simple—just an email address and password are enough. The free plan offers plenty of features to get started. Once you've signed up and logged in, you can begin by creating your first repository . A GitHub repository is like a dedicated folder for your project—it keeps your code organized and version-controlled. Creating a Repository After logging in, click the “Create repository” button. You'll need to fill in the following fields: Repository name : Choose a name for your repository. Note: Spaces are not allowed. Description (optional) : A short description of your project. Public / Private : Choose whether to make your repository public or private. Initialize this repository with: README.md : A file to describe your...