Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error: cs0246 1

Status
Not open for further replies.

ksbrace

Programmer
May 13, 2000
501
US
Hello,
I am trying to work through this tutorial on C# and I am having difficulties at the moment. I am getting these 2 errors:
DegC.cs(8,14): error CS0246: The type or namespace name 'DegF' could not be found (are you missing a using directive or an assembly reference?)
DegC.cs(13,20): error CS0246: The type or namespace name 'IReversibleConversion'could not be found (are you missing a using directive or an assembly reference?)

I have 6 small .cs files in my project. I am compiling on the command line with: csc DegC.cs /main:DegC
I have pasted my files below in hopes that someone can shed some light as to what the problem is. I looked up the error on MSDN, but it doesn't seem to relate to my problem(s). Thanks in advance! Kelly
Code:
//DegC.cs:
using System;
namespace Conversion
{
	/// <summary>
	///   takes degrees Fahrenheit from the command line,
	///   prints degrees Celsius.
	/// </summary>
	class DegC: DegF 
	{
		/// <summary>
		///   insert a different Conversion object.
		/// </summary>
		protected static IReversibleConversion conversionC = new ReversibleLinearConversion(9.0/5, 32.0).inverse();
	
		/// <summary>
		///   hand command line to <c>DegF</c>.
		///   Necessary because <c>main</c> has to be in assembly.
		/// </summary>
		public static void Main (string[] args)
		{
			DegF.Main(args);
		}
	}
}
-------------
// DegF.cs
using Console = System.Console;
namespace Conversion
{

	/// <summary>
	///   takes degrees Celsius from the command line,
	///   prints degrees Fahrenheit.
	///   Version with objects.
	/// </summary>
	class DegF 
	{
		/// <summary>
		///   a <see cref=&quot;IConversion&quot;>IConversion</see> object,
		///   initialized to convert from degrees Celsius
		///   to degrees Fahrenheit.
		/// </summary>
		protected static IConversion conversionF =
			new LinearConversion(9.0/5, 32.0); // cannot write 9. 32.
		/// <summary>
		///   runs values from the command line through a
		///   <see cref=&quot;conversion&quot;>conversion</see> object.
		/// </summary>
		/// <param name=&quot;args&quot;>words from the command line</param>
		public static int Main (string[] args) 
		{
			if (args != null)
			
				for (int a = 0; a < args.GetLength(0); ++ a) 
				{
					double x = double.Parse(args[a]);
					Console.WriteLine(&quot;\t&quot;+ conversion.Y(x));
				}
			return 0;
		}
	}	
}
-----------------
// IConversion.cs
namespace Conversion
{
	/// <summary>
	///   what a conversion object must do.
	/// </summary>
	public interface IConversion 
	{
		/// <summary>
		///   computes a function value.
		/// </summary>
		/// <param name=&quot;x&quot;>function argument</param>
		double Y (double x); // public
	}

}
---------------------
using System;
namespace Conversion
{
	/// <summary>
	///   an <c>IConversion</c> which can be inverted.
	///   Placed in same assembly because referenced component names
	///   must be unique.
	/// </summary>
	public interface IReversibleConversion: IConversion 
	{
		IConversion inverse (); // public
	}
}
---------------------
// LinearConversion.cs
namespace Conversion
{
	/// <summary>
	///   implements a linear transformation.
	/// </summary>
	class LinearConversion: IConversion 
	{
		/// <summary>
		///   immutable coefficients of the transformation.
		/// </summary>
		readonly double _a, _b;
		/// <summary>
		///   read access to coefficient of the transformation.
		/// </summary>
		public double a { get { return _a; }}
		/// <summary>
		///   read access to constant coefficient of the transformation.
		/// </summary>
		public double b { get { return _b; }}
		/// <summary>
		///   initializes the coefficients of the transformation.
		/// </summary>
		public LinearConversion (double a, double b) 
		{
			_a = a; _b = b;
		}
		/// <returns><see cref=&quot;a&quot;>a</see>*x + <see cref=&quot;b&quot;>b</see></returns>.
		public double Y (double x) 
		{
			return a*x + b;
		}
	}
}
-----------------------
//ReversibleLinearConversion
using System;
namespace Conversion
{

	/// <summary>
	///   implements linear transformation with inverse.
	///   Placed in same assembly because referenced component names
	///   must be unique.
	/// </summary>
	class ReversibleLinearConversion: LinearConversion, IReversibleConversion 
	{
		/// <summary>
		///   initializes the coefficients of the transformation.
		/// </summary>
		public ReversibleLinearConversion (double a, double b) :base(a, b)
		{
			
		}
		/// <summary>
		///   returns inverse transformation.
		///   Java needs to call <c>get</c>-methods generated by C#.
		/// </summary>
		public IConversion inverse () 
		{
			return new LinearConversion(1/get_a(), - get_b()/get_a());
		}
	}
}
 
Have you tried:
[tt]csc DegC.cs DegF.cs IConversion.cs etc /main:DegC[/tt]

(I would've listed all your file names instead of the etc, but you skipped one of the names in your question.)
 
Rosenk,
Thanks!!!, that eliminated those 2errors, and I was getting another error about having 2 Main methods and to make one of them with the new keyword, which I did. But now I am getting this one:
error CS1555: Could not find 'DegC' specified for Main method

here's the DegC
Code:
class DegC: DegF 
	{
		/// <summary>
		///   insert a different Conversion object.
		/// </summary>
		protected static IReversibleConversion conversionC = new ReversibleLinearConversion(9.0/5, 32.0).inverse();
	
		/// <summary>
		///   hand command line to <c>DegF</c>.
		///   Necessary because <c>main</c> has to be in assembly.
		/// </summary>
		 public static new void Main (string[] args)
		{
			DegF.Main(args);
		}
	}
 
AFAIK, you can only have one Main method in an EXE project.

Chip H.
 
You can specify where your entry point is: by saying csc *.cs /main:DegC on the command line if you have more than one Main, this tells it to start w/DegC.Main(). I ended up fixing the problem by making the one Main w/new keyword. I must not have saved it in the IDE when I tried to compile it on the command line. Thanks for your response Chip.
 
The complaint came because you had a static void Main() in both DegC and the class it inherits from, DegF. (You would have gotten the error you got even if it were not the function Main() ... you can't implicitly replace a function without indicating that you know you're doing it with the [tt]new[/tt] tag.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top