public class Program
{
private static readonly ILog logger = log4net.LogManager.GetLogger
(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
logger.Debug("Starting the main driver program");
ShapeManager manager = new ShapeManager("data.txt");
manager.DisplayShapes();
logger.Debug("Exiting the main program");
System.Console.ReadLine();
_______________________________
public class ShapeManager
{
private static readonly ILog logger =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private string datafile;
private List<Shape> shapes;
private StreamReader sr;
public ShapeManager()
{
}
public ShapeManager(string datafile)
{
logger.Debug("Starting manager");
this.datafile = datafile;
shapes = new List<Shape>();
}
public void ReadDataFile()
{
string line;
double xcoord;
double ycoord;
double radius;
double height;
double width;
sr = new StreamReader(datafile);
Shape tempshape = null;
while (!sr.EndOfStream)
{
line = sr.ReadLine();
var elements = line.Split('|');
xcoord = Convert.ToDouble(elements[1]);
ycoord = Convert.ToDouble(elements[2]);
radius = Convert.ToDouble(elements[3]);
width = Convert.ToDouble(elements[3]);
height = Convert.ToDouble(elements[4]);
if (elements[0].ToLower().Equals("c"))
{
tempshape = new Circle(xcoord, ycoord, radius);
}
if (elements[0].ToLower().Equals("r"))
{
tempshape = new Rectangle(xcoord, ycoord, width, height);
}
shapes.Add(tempshape);
}
sr.Close();
sr.Dispose();
}
public void DisplayShapes()
{
foreach (Shape temp in shapes)
{
temp.Display();
}
}
这是data.txt文件
c | 1.1 | 2.2 | 3.3 r | 1.1 | 2.2 | 3.3 | 4.4 c | 2.2 | 3.3。| 4.4 r | 2.2 | 3.3 | 4.4。| 5.5
我假设我的问题不在主程序本身,而是在shapemanager的displayshape方法下。我似乎不知道。我还没有发布其他3个课程,但我不认为这些课程会导致我遇到问题。