C#中我 编写的代码 显示 不包含适合于入口点的静态“Main”方法
usingSystem;classDaysTemp{//字段privateintHigh=75;privateintLow=45;//方法privateintGetHig...
using System;
class DaysTemp
{
//字段
private int High = 75;
private int Low = 45;
//方法
private int GetHigh()
{
return High;
}
private int GetLow()
{
return Low;
}
public float Average()
{
return (GetHigh()+GetLow())/2;
}
} 展开
class DaysTemp
{
//字段
private int High = 75;
private int Low = 45;
//方法
private int GetHigh()
{
return High;
}
private int GetLow()
{
return Low;
}
public float Average()
{
return (GetHigh()+GetLow())/2;
}
} 展开
1个回答
展开全部
首先,你这段程序建立了一个简单的类DaysTemp,要运行它需要一个静态的主函数入口,即静态Main方法,在Main方法中创建这个类的实例并调用Average方法。
比如,你可以直接在类中建立Main方法,如下
using System;
class DaysTemp
{
//字段
private int High = 75;
private int Low = 45;
//方法
private int GetHigh()
{
return High;
}
private int GetLow()
{
return Low;
}
public float Average()
{
return (GetHigh() + GetLow()) / 2;
}
static void Main(string[] args)
{
DaysTemp myDaysTemp = new DaysTemp();
float f = myDaysTemp.Average();
Console.WriteLine(f);
Console.Read();
}
}
也可以新建一个类单独用来运行,如下:
using System;
class DaysTemp
{
//字段
private int High = 75;
private int Low = 45;
//方法
private int GetHigh()
{
return High;
}
private int GetLow()
{
return Low;
}
public float Average()
{
return (GetHigh() + GetLow()) / 2;
}
}
class Program
{
static void Main(string[] args)
{
DaysTemp myDaysTemp = new DaysTemp();
float f = myDaysTemp.Average();
Console.WriteLine(f);
Console.Read();
}
}
比如,你可以直接在类中建立Main方法,如下
using System;
class DaysTemp
{
//字段
private int High = 75;
private int Low = 45;
//方法
private int GetHigh()
{
return High;
}
private int GetLow()
{
return Low;
}
public float Average()
{
return (GetHigh() + GetLow()) / 2;
}
static void Main(string[] args)
{
DaysTemp myDaysTemp = new DaysTemp();
float f = myDaysTemp.Average();
Console.WriteLine(f);
Console.Read();
}
}
也可以新建一个类单独用来运行,如下:
using System;
class DaysTemp
{
//字段
private int High = 75;
private int Low = 45;
//方法
private int GetHigh()
{
return High;
}
private int GetLow()
{
return Low;
}
public float Average()
{
return (GetHigh() + GetLow()) / 2;
}
}
class Program
{
static void Main(string[] args)
{
DaysTemp myDaysTemp = new DaysTemp();
float f = myDaysTemp.Average();
Console.WriteLine(f);
Console.Read();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询