gpt4 book ai didi

c# - .NET 库编辑后无需重新编译程序

转载 作者:太空宇宙 更新时间:2023-11-03 20:00:27 25 4
gpt4 key购买 nike

请考虑这种情况:

public class TestType
{
public string a
{
get;
set;
}
public string b
{
get;
set;
}

public override string ToString()
{
return string.Format("a: \"{0}\"\tb:\"{1}\"", a, b);
}
}

TestType 类被编译到一个类库中,然后我在这个简单的程序中使用它:

    static void Main(string[] args)
{
TestType tP = new TestType();
tP.a = "a";
tP.b = "b";
Console.WriteLine(tP.ToString());
Console.ReadKey(true);
}

显然它有效(正确执行没有错误)。

输出:a: "a"b:"b"

然后我像这样编辑库中的类:

public class TestType
{
public string a
{
get;
set;
}
public string b
{
get;
set;
}
public string c
{
get;
set;
}

public override string ToString()
{
return string.Format("a: \"{0}\"\tb:\"{1}\"\tc:\"{2}\"", a, b, c);
}
}

我只重新编译库并重新运行程序(不重新编译)。现在我预计程序会崩溃,因为它不知道类的更改,但它可以工作。

输出:a: "a"b:"b"c:""

如果类型与它知道的类型不同,它如何工作?

最佳答案

.NET DLL 具有一定程度的向后兼容性。添加字段不是 binary-breaking change

关于c# - .NET 库编辑后无需重新编译程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29072616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com