我有一个接口定义为:
public interface MyInterface {
object foo { get; set; };
}
Run Code Online (Sandbox Code Playgroud)
以及实现该接口的类:
public class MyClass : MyInterface {
object foo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后我创建一个返回ICollection的函数,如下所示:
public ICollection<MyClass> Classes() {
List<MyClass> value;
List<MyInterface> list = new List<MyInterface>(
new MyInterface[] {
new MyClass {
ID = 1
},
new MyClass {
ID = 1
},
new MyClass {
ID = 1
}
});
value = new List<MyClass>((IEnumerable<MyClass>) list);
return value;
}
Run Code Online (Sandbox Code Playgroud)
它会编译,但会抛出一个
无法转换'System.Collections.Generic.List
1[MyInterface]' to type 'System.Collections.Generic.IEnumerable1 [MyClass]' 类型的对象. …
如何使用RemoveHandler匿名方法?
这是我为MyEvent类的事件添加处理程序的方法MyClass:
AddHandler MyClass.MyEvent, Sub()
'...
End Sub
Run Code Online (Sandbox Code Playgroud)
然后我如何使用RemoveHandler删除MyEvent事件的处理程序?
我在App_Code中创建了一个新类
namespace Site {
public class MyClass {
public MyClass() {
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Global.asax.cs
namespace Site {
public class Global : System.Web.HttpApplication {
protected void Application_Start(object sender, EventArgs e) {
*MyClass myClass = new MyClass();*
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误发生在:MyClass myClass = new MyClass();
找不到类型或命名空间名称'MyClass'(您是否缺少using指令或程序集引用?)
我在这里错过了什么?
这是我的界面:
public interface MyInterface {
bool Foo();
}
Run Code Online (Sandbox Code Playgroud)
这是我的抽象类:
public abstract class MyAbstractClass : MyInterface {
abstract bool MyInterface.Foo();
}
Run Code Online (Sandbox Code Playgroud)
这是编译器错误: "修饰符'abstract'对此项无效.
我应该如何继续使用抽象方法显式实现抽象?
这是我的代码:
void Main()
{
StarTrek baseClass = new StarTrek();
NewGeneration childClass = new NewGeneration();
baseClass.ShowEnum();
childClass.ShowEnum();
}
public class StarTrek
{
internal enum Characters
{
Kirk, Spock, Sulu, Scott
}
public void ShowEnum()
{
Type reflectedEnum = typeof(Characters);
IEnumerable<string> members = reflectedEnum.GetFields()
.ToList()
.Where(item => item.IsSpecialName == false)
.Select(item => item.Name);
string.Join(", ", members).Dump();
}
}
public class NewGeneration : StarTrek
{
internal new enum Characters
{
Picard, Riker, Worf, Geordi
}
}
Run Code Online (Sandbox Code Playgroud)
ShowEnum始终显示:
柯克,斯波克,苏禄,斯科特
即使它是在NewGeneration类中调用的.我错过/误解了什么吗?ShowEnum有没有办法使用NewGeneration.Characters而不是StarTrek.Characters?
我通过连接到SQL Server 2005数据库创建了我的DataClasses .如果我的应用程序要连接到SQL Server 2000数据库,是否需要重新编译?
SQL Server 2000不支持ROW_NUMBER()函数.我正在使用LINQ to SQL的Skip()和Take()方法来浏览我的记录.LINQ to SQL是否会正确生成正确的SQL查询,尽管它被编译为连接到较新版本的SQL Server?
试过这个:
Remove-Item "C:\foo\.svn"
Run Code Online (Sandbox Code Playgroud)
但这是我遇到的错误
Remove-Item : Cannot find path 'C:\foo\.svn' because it does no
t exist.
At line:1 char:12
+ Remove-Item <<<< "C:\foo\.svn"
+ CategoryInfo : ObjectNotFound: (C:\foo\.svn:String) [Remove-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Run Code Online (Sandbox Code Playgroud) c# ×3
interface ×2
.net ×1
abstract ×1
addhandler ×1
app-code ×1
asp.net ×1
enums ×1
generics ×1
global-asax ×1
linq-to-sql ×1
overloading ×1
powershell ×1
sql-server ×1
vb.net ×1