读书人

c#高级编程 里面的例子如何不对啊

发布时间: 2012-01-13 22:43:30 作者: rapoo

c#高级编程 里面的例子怎么不对啊?
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;


namespace ConsoleApplication1
{
public class UserPrefernces
{
public static readonly Color BackColor;

static UserPreferences()
{
DateTime now=DateTime.Now;
if(now.DayOfWeek==DayOfWeek.Saturday||now.DayOfWeek==DayOfWeek.Sunday)
BackColor=Color.Green;
else
BackColor=Color.Red;
}

private UserPreferences()
{
}
}

class MainEntryPoint

{

static void Main(string[] args)
{
Console.WriteLine( "User-Preferences: BackColor is: "+UserPrefernces.BackColor.ToString());
}
}
}

我这都是照着书写的,但是编译提示说
“类、结构或接口方法必须有返回类型”
无法编译啊,怎么回事???

[解决办法]
拼写错误
你的类名是 UserPrefernces
而构造函数名是 UserPreferences

读书人网 >C#

热点推荐