我已经完成了制作程序的作业,该程序由2个单独的项目组成,包含方形,矩形和平行六面体的类,并且能够计算它们的区域。我认为我已经正确地完成了所有事情并连接了项目,但是当我尝试编译代码时,我不断收到此错误消息:
程序*不包含静态' Main'适合入境点的方法。
我的两个项目都有静态主要方法。
第一个项目
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace zad8
{
public abstract class CFormulas
{
abstract public double S();
abstract public double P();
abstract public double SF();
abstract public double V();
}
public class CSquare : CFormulas
{
double a { get; set; }
public CSquare(double a)
{ this.a = a; }
public override double S() { return a * a; }
public override double P() { return 4 * a; }
}
public class CRectangular : CFormulas
{
public double a { get; set; }
public double b { get; set; }
public CRectangular(double a, double b)
{
this.a = a;
this.b = b;
}
public override double S() { return a * b; }
public override double P() { return 2 * (a + b); }
}
class zad
{
static void Main(string[] args)
{
CSquare f1 = new CSquare(5);
Console.WriteLine("Лицето на квадрата е {0}, а периметъра е {1}.", f1.S(), f1.P());
CRectangular f2 = new CRectangular(2, 3);
Console.WriteLine("Лицето на правоъгълника е {0}, а периметъра е {1}.", f2.S(), f2.P());
Console.ReadKey(true);
}
}
}
第二个项目
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using zad8;
namespace zad8
{
class CParallelepiped : CRectangular
{
public CParallelepiped(double a, double b, double h) : base(a, b) {
this.h = h;
this.a = a;
this.b = b;
}
double h { get; set; }
//public CParallelepiped(double h) { this.h = h; }
public override double SF() { return 2 * (a*b+b*h+h*a); }
public override string ToString()
{
return string.Format("Пълната повърхнина на фигурата е {0}",SF());
}
public override double V() { return a*b* h; }
public override string ToString() { return string.Format("Обема на фигурата е {0}", V()); }
}
class Program
{
static void Main(string [] args)
{
//CParallelepiped f3 = new CParallelepiped(1,2,3);
//Console.WriteLine("Пълната повърхнина на паралелепипеда е {0}.", f3.SF());
Console.ReadKey(true);
}
}
}
答案 0 :(得分:0)
您的实现中存在一些问题,但Main方法不是其中之一。
CParallelepiped
以下代码编译:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using zad8;
namespace zad8
{
public abstract class CFormulas
{
abstract public double S();
abstract public double P();
abstract public double SF();
abstract public double V();
}
public class CSquare : CFormulas
{
double a { get; set; }
public CSquare(double a)
{ this.a = a; }
public override double S() { return a * a; }
public override double P() { return 4 * a; }
public override double SF()
{
throw new NotImplementedException();
}
public override double V()
{
throw new NotImplementedException();
}
}
public class CRectangular : CFormulas
{
public double a { get; set; }
public double b { get; set; }
public CRectangular(double a, double b)
{
this.a = a;
this.b = b;
}
public override double S() { return a * b; }
public override double P() { return 2 * (a + b); }
public override double SF()
{
throw new NotImplementedException();
}
public override double V()
{
throw new NotImplementedException();
}
}
class CParallelepiped : CRectangular
{
public CParallelepiped(double a, double b, double h) : base(a, b) {
this.h = h;
this.a = a;
this.b = b;
}
double h { get; set; }
//public CParallelepiped(double h) { this.h = h; }
public override double SF() { return 2 * (a*b+b*h+h*a); }
public override double V() { return a*b* h; }
public override string ToString() { return string.Format("Обема на фигурата е {0}", V()); }
}
class Program
{
static void Main(string [] args)
{
//CParallelepiped f3 = new CParallelepiped(1,2,3);
//Console.WriteLine("Пълната повърхнина на паралелепипеда е {0}.", f3.SF());
Console.ReadKey(true);
}
}
}