fr00ty_l00ps
fr00ty_l00ps

Reputation: 730

How do I fix "The type or namespace name could not be found"?

This is a followup to my earlier question https://codereview.stackexchange.com/questions/12165/efficency-in-c/12169, and I tried my best to use BigIntegers in place of the ulongs, but I must have done something wrong. I am new to C#, and I am familiar with Java. This was my best shot at conversion:

using System;

namespace System.Numerics{

      public class Factorial{

             public static void Main(){

             String InString = Console.ReadLine();

             BigInteger num = 0;

             BigInteger factorial = 1;

             try {
                 num = BigInteger.Parse(InString);
                 Console.WriteLine(num);
                 }
             catch (FormatException) {

                  Console.WriteLine("Unable to convert the String into a BigInteger");
            }



            for (BigInteger forBlockvar = num; forBlockvar > 1; forBlockvar--){

                     factorial *= forBlockvar;

            }

            Console.WriteLine("The Factorial for the Given input is:");

            Console.WriteLine(factorial);
    }
}
}

And I got the following errors:

prog.cs(11,18): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(13,18): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(26,22): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference?

What does this error mean and how do I fix it?

Upvotes: 7

Views: 9778

Answers (2)

JimmyTheCode
JimmyTheCode

Reputation: 5694

I had to add assembly references:

  1. Go to References and Properties

enter image description here

  1. Click the "Add..." button at the bottom of the new window. Click browse and find the .dll file relating to the namespace you want. For example my path is:
C:\My-Folder\My-Project-Name.ViewModel\bin\Debug\My-Project-Name.ViewModel.dll
  1. Once I'd done this, I could add the relevant namespace in the "Additional Namespace Imports" tab:

enter image description here

Simply type the namespace on a new line in the textfield.

Upvotes: 0

Jesse C. Slicer
Jesse C. Slicer

Reputation: 20157

You need to add a reference (right-click on References in the Solution Explorer and select Add Reference) to System.Numerics.dll.

Also, put in using System.Numerics rather than having your method's namespace be that (i.e. name it something more descriptive for your codebase).

Upvotes: 11

Related Questions