Friday, 28 February 2025

Different ways to install Nuget Package in Visual Studio 2022

In this tutorial, I’ll show you different ways to install a NuGet package in Visual Studio 2022. NuGet is the package manager for .NET, and it’s essential for adding libraries and tools to your projects. Whether you’re a beginner or an experienced developer, this guide will walk you through the process step-by-step.

Installing NuGet packages is a common task in .NET development, and Visual Studio 2022 makes it incredibly easy. Below, I’ve embedded a YouTube video tutorial that demonstrates the entire process. Watch the video to see it in action, or follow the written steps below.

Different Ways to Install a NuGet Package in Visual Studio 2022:

  1. Using the NuGet Package Manager:
    • Right-click on your project in the Solution Explorer.
    • Select Manage NuGet Packages.
    • Search for the package you want to install (e.g., Newtonsoft.Json).
    • Click Install.
  2. Using the Package Manager Console:
    • Open the Package Manager Console from Tools > NuGet Package Manager > Package Manager Console.
    • Run the command: Install-Package PackageName (replace PackageName with the name of the package).
  3. Using the .NET CLI:
    • Open a terminal or command prompt.
    • Navigate to your project directory.
    • Run the command: dotnet add package PackageName.

If you encounter any issues during the installation, feel free to leave a comment below, and I’ll be happy to help! Don’t forget to like, share, and subscribe to my YouTube channel for more programming tutorials.

Why Use NuGet? NuGet simplifies the process of adding third-party libraries to your .NET projects. It handles dependencies, updates, and versioning, making your development workflow more efficient. Whether you’re working on a small project or a large enterprise application, NuGet is a must-have tool.

Fix git src refspec master does not match any, failed to push some refs in git and github

Are you encountering the "git src refspec master does not match any, failed to push some refs" error while trying to push your commits to GitHub? Don’t worry! In this tutorial, I’ll walk you through the steps to fix this common Git error and get your code pushed successfully.

This error usually occurs when Git can’t find the branch you’re trying to push or when there are no commits to push. Watch the video tutorial above for a visual guide, or follow the steps below:

Steps to Fix the Error:

  1. Verify your remote URL with git remote -v.
  2. Create an initial commit if your branch is empty using git commit -m "Initial commit".
  3. Push your branch to GitHub using git push origin branch-name.
  4. Check if you’re on the correct branch using git branch.

For a more detailed explanation, watch the video tutorial embedded above. If you found this guide helpful, feel free to leave a comment below or share it with others who might benefit from it!

Friday, 31 January 2025

Unable to add controller to ASP.NET, Controller option greyed out / disabled

 If you are unable to add controller to ASP.NET due to controller option being greyed out. Please check out my 1 minute youtube video which provides solution to this issue. 

Thank you very much,




Thursday, 30 January 2025

Monday, 27 January 2025

Thursday, 23 January 2025

Understanding C# Interface under 10 minutes with example and a coding challenge

 I've linked my YouTube video below, where I explain interface in C# with a practical example and a fun coding challenge at the end. Below the video, you'll find the actual code featured in the tutorial.

Try solving the coding challenge yourself before checking out the solution provided at the end of this blog - it’s a fantastic way to test your understanding and sharpen your skills! Happy coding! 😊




Actual code featured in the tutorial

using System;
using System.Collections.Generic;

namespace Interface_App
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List flyingThings = new List
            {
                new People(),
                new Airplane()
            };

            foreach (var thing in flyingThings)
            {
                thing.Fly();
                thing.Glide();
                Console.WriteLine();
            }

            List speakingThings = new List
            {
                new People()
            };

            foreach (var thing in speakingThings)
            {
                thing.Speak();
                Console.WriteLine();
            }
        }      
        
    }


    interface IAirActivities
    {
        void Fly();
        void Glide();
    }

    interface ISpeaking
    {
        void Speak();
    }

    public class People : IAirActivities, ISpeaking
    {
        public void Fly()
        {
            Console.WriteLine("People who fly airplanes are called pilot.");
        }

        public void Glide()
        {
            Console.WriteLine("People can glide in the air using gliders.");
        }

        public void Speak()
        {
            Console.WriteLine("People can speak at least one language.");
        }
    }
    
    public class Airplane : IAirActivities
    {
        public void Fly()
        {
            Console.WriteLine("Airplanes are able to fly in the sky");
        }

        public void Glide()
        {
            Console.WriteLine("Airplanes can glide with their engines off");
        }
    }

}



Interface coding challenge solution

Below is the solution to the coding challenge featured in the video. 


using System;
using System.Collections.Generic;


namespace InterfaceExcerciseApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            IAnimal lion = new Lion();
            IAnimal parrot = new Parrot();
            IAnimal snake = new Snake();
            
            List animals = new List { lion, parrot, snake};
            

            foreach (IAnimal animal in animals)
            {
                Console.WriteLine(animal.Eat());
                Console.WriteLine(animal.MakeSound());
                Console.WriteLine();
            }
        }
    }

    public interface IAnimal
    {
        string Eat();
        string MakeSound();
    }

    public class Lion : IAnimal
    {
        public string Eat()
        {
            return "Lions eat meat";
        }

        public string MakeSound()
        {
            return "Lion roars"; 
        }   
    }

    public class Parrot : IAnimal
    {
        public string Eat()
        {
            return "Parrots eat nuts.";
        }

        public string MakeSound()
        {
            return "Parrots sing";
        }
    }

    public class Snake : IAnimal
    {
        public string Eat()
        {
            return "Snakes eat rodents.";
        }

        public string MakeSound()
        {
            return "Snakes hiss.";
        }
    }
}


Thursday, 16 January 2025

CSharp C# Method Overloading with Practical Example and Coding Challenge / Coding Excercise

I've linked my YouTube video below, where I explain method overloading in C# with a practical example and a fun coding challenge at the end. Below the video, you'll find the actual code featured in the tutorial.

Try solving the coding challenge yourself before checking out the solution provided at the end of this blog - it’s a fantastic way to test your understanding and sharpen your skills! Happy coding! 😊





Actual code featured in the tutorial


using System;

namespace MethodOverLoading
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Log log = new Log();
            log.DisplayLog("Welcome to this program.");
            log.DisplayLog("You have successfully created the file on ", DateTime.Now);
            log.DisplayLog("Requires user authentication", 401);
        }
    }

    public class Log
    {
        public void DisplayLog(string message)
        {
            Console.WriteLine(message);
        }
        public void DisplayLog(string message, DateTime dateAndTime)
        {
            Console.WriteLine($"{message}, {dateAndTime}");
        }
        public void DisplayLog(string error, int errorCode)
        {
            Console.WriteLine($"{error}, error code: {errorCode}");
        }
    }
}



Method Overloading coding challenge solution

Below is the solution to the coding challenge featured in the video. In this example, I’ve used the double data type for the square and rectangle area parameters, and int for the circle area. However, feel free to use any data types you prefer—as long as the method signatures are different, your solution will work perfectly for this challenge.


using System;

namespace MethodOverLoadingExcercise
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Area(3.0);
            Area(1.5, 4);
            Area(4);
        }

        //area of a square
        public static double Area(double length)
        {
            //if decimal, then round to 2 decimal places
            double output = Math.Round(length * length, 2);

            Console.WriteLine($"Area of square: {output}");

            return output;
        }

        //area of a rectangle
        public static double Area(double length1, double length2)
        {
            double output = Math.Round(length1 * length2, 2);

            Console.WriteLine($"Area of rectangle: {output}");

            return output;
        }

        /* area of a circle
        We use an integer parameter for the radius to make this 
        method's signature unique compared to the square's area method. 
        This is important because both shapes involve a single numeric input.
         */
        public static double Area(int radius)
        {
            //const means variable is a constant
            const double pi = Math.PI;

            //Area of a circle = pi * r * r, rounded to 2 decimals
            double output = Math.Round(pi * radius * radius, 2);

            Console.WriteLine($"Area of circle: {output}");

            return output;
        }
    }
    
}