在C#中是否可以使用类型比较器(如果它们存在)比较两个未知类型的对象(包括引用和值类型)?
目标是编写一个具有如下签名的函数:
public bool Compare(object a, object b)
{
// compare logic goes here
}
Run Code Online (Sandbox Code Playgroud)
哪会回来
Compare(100d, 100d) == true
Compare(100f, 100f) == true
Compare("hello", "hello") == true
Compare(null, null) == true
Compare(100d, 101d) == false
Compare(100f, null) == false
// Use type comparators where possible, i.e.:
Compare(new DateTime(2010, 12, 01), new DateTime(2010, 12, 01)) == true
Compare(new DateTime(2010, 12, 01), new DateTime(2010, 12, 02)) == false
Compare(new DateTime(2010, 12, 01), null) == false
Run Code Online (Sandbox Code Playgroud)
有没有一种通用的方法来解决这个问题,适用于任何类型的对象?
也许我不能正确理解MVC区域是如何工作的,但这让我有些困惑.
所以此时如果你启动应用程序并导航到/ MyArea /它应该加载AnArea控制器及其匹配视图.如果导航到/ MyArea/AnArea,它将显示相同的结果.
但是,如果您导航到/ AnArea /,仍然会找到控制器并显示以下错误消息:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/anarea/Index.aspx
~/Views/anarea/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/anarea/Index.cshtml
~/Views/anarea/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Run Code Online (Sandbox Code Playgroud)
这是正确的行为吗?我原以为一个区域的控制器只能通过它自己的区域访问而不是全局访问.