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 /mainegC
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
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 /mainegC
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="IConversion">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="conversion">conversion</see> object.
/// </summary>
/// <param name="args">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("\t"+ 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="x">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="a">a</see>*x + <see cref="b">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());
}
}
}