在执行重构时,我最终创建了一个类似下面示例的方法.为简单起见,数据类型已更改.
我之前有一个这样的赋值语句:
MyObject myVar = new MyObject();
Run Code Online (Sandbox Code Playgroud)
它是偶然重构的:
private static new MyObject CreateSomething()
{
return new MyObject{"Something New"};
}
Run Code Online (Sandbox Code Playgroud)
这是我的剪切/粘贴错误的结果,但new关键字in private static new有效并编译.
问题:new关键字在方法签名中表示什么?我假设它是在C#3.0中引入的东西?
这有override什么不同?
问题非常简单,
如果我有以下课程:
public class ExportReservationsToFtpRequestOld
{
public int A { get; set; }
public long B { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并将其更改为:
public class ExportReservationsToFtpRequestOld
{
public virtual int A { get; set; }
public virtual long B { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
它可以打破一个合法的客户端DLL吗?
我有这个代码:
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Foo foo = new Foo();
Bar bar = new Bar();
Baz baz = new Baz();
Foo fooBar = new Bar();
Foo fooBaz = new Baz();
Bar barBaz = new Baz();
foo.Test();
bar.Test();
baz.Test();
fooBar.Test();
fooBaz.Test();
barBaz.Test();
Console.ReadLine();
}
}
internal class Foo
{
public virtual void Test()
{
Console.WriteLine("Foo");
}
}
internal class Bar : Foo
{
public new virtual void Test()
{
Console.WriteLine("Bar");
}
} …Run Code Online (Sandbox Code Playgroud)