刚学了接口。。于是根据书《Head First的c#》里的例题写了个程序,其中有一段是这样
-----------------------------------------------类代码----------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public class TallGuy:IClown
{
public string Name;
public int Height;
public void TalkAboutYourself()
{
System.Windows.Forms.MessageBox.Show("My name is" + Name + "and I'm" + Height + "inches tall.");
}
public string FunnyThingIHave
{
get;
}
public void Honk()
{
MessageBox.Show("Test");
}
}
-----------------------------------------------类代码----------------------------------------------- 上边的get底下老是有一条波浪线提示有问题:错误 1 “WindowsFormsApplication1.TallGuy.FunnyThingIHave.get”必须声明主体,因为它未标记为 abstract 或 extern。自动实现的属性必须同时定义 get 访问器和 set 访问器。 E:\filessss\Visual Studio 2010\Projects\WindowsFormsApplication6\WindowsFormsApplication6\TallGuy.cs 19 13 WindowsFormsApplication6
后来我上网查了下 有说版本问题 我的是2010肯定没问题
还有就是说要在get后补充内容
于是我就补了(书上本来也有这个的)
-----------------------------------------------补充代码-----------------------------------------------
public string FunnyThingIHave
{
get { return "big shoes"; }
}
-----------------------------------------------补充代码-----------------------------------------------可还是不行
-----------------------------------------------这是接口代码-----------------------------------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
interface IClown
{
void Honk();
string FunnyThingIHave{get;} }
}
-----------------------------------------------这是接口代码-----------------------------------------------
为什么会这样呢 而且我在书的前面也确实看到了可以只输入get;这样的 没必要输入后边的东西了啊。。搓脸中。
-----------------------------------------------类代码----------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public class TallGuy:IClown
{
public string Name;
public int Height;
public void TalkAboutYourself()
{
System.Windows.Forms.MessageBox.Show("My name is" + Name + "and I'm" + Height + "inches tall.");
}
public string FunnyThingIHave
{
get;
}
public void Honk()
{
MessageBox.Show("Test");
}
}
-----------------------------------------------类代码----------------------------------------------- 上边的get底下老是有一条波浪线提示有问题:错误 1 “WindowsFormsApplication1.TallGuy.FunnyThingIHave.get”必须声明主体,因为它未标记为 abstract 或 extern。自动实现的属性必须同时定义 get 访问器和 set 访问器。 E:\filessss\Visual Studio 2010\Projects\WindowsFormsApplication6\WindowsFormsApplication6\TallGuy.cs 19 13 WindowsFormsApplication6
后来我上网查了下 有说版本问题 我的是2010肯定没问题
还有就是说要在get后补充内容
于是我就补了(书上本来也有这个的)
-----------------------------------------------补充代码-----------------------------------------------
public string FunnyThingIHave
{
get { return "big shoes"; }
}
-----------------------------------------------补充代码-----------------------------------------------可还是不行
-----------------------------------------------这是接口代码-----------------------------------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
interface IClown
{
void Honk();
string FunnyThingIHave{get;} }
}
-----------------------------------------------这是接口代码-----------------------------------------------
为什么会这样呢 而且我在书的前面也确实看到了可以只输入get;这样的 没必要输入后边的东西了啊。。搓脸中。
解决方案 »
- winform中如何算出答题的总分
- 关于sqlconnection语句的写法问题!
- 对ado.net的数据库开发流程不了,感觉脑袋好乱啊!有人帮帮我吗?
- 怎么获得windows信使服务(net send……)中收到的信息的内容啊!~
- C# 动态创建按钮,怎么获得按钮事件 求帮助
- C# WebBrowser 问题
- C#调用 fortran生成的DLL 计算速度比在Fotran黑窗口下的计算速度慢好几倍,是什么原因?
- 给分啦,大家都来参加......
- 怎样在dataGrid的单元格中写数据?
- 如何让 C# 支持 VBScript 脚本化?
- ADO.NET 流类型数据的问题
- 请问NET4里面并发的数据类型里面哪个和LIST是一致的?
{
get;
}
=>
public string FunnyThingIHave { get; private set; }
想简单点可以这样,
注意必须同时定义 get 访问器和 set 访问器。
至于修饰符就看你项目需要了
我的ide就是2010的 书上的是2008的 但我想这两个版本对这个应该没什么影响把