小编Dua*_*ane的帖子

C#比较两个未知类型的对象(包括引用和值类型)

在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)

有没有一种通用的方法来解决这个问题,适用于任何类型的对象?

.net c#

38
推荐指数
3
解决办法
2万
查看次数

ASP.NET MVC3区域控制器可从全局路由访问?

也许我不能正确理解MVC区域是如何工作的,但这让我有些困惑.

  1. 使用在MVC3项目上的Visual Studio中右键单击"添加区域"添加名为"MyArea"的区域
  2. 为MyArea创建一个控制器:在MyArea区域中具有匹配视图的"AnArea".
  3. 将"controller ="AnArea"添加到MyAreaAreaRegistration.RegisterArea方法中的context.MapRoute的defaults参数中.

所以此时如果你启动应用程序并导航到/ 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)

这是正确的行为吗?我原以为一个区域的控制器只能通过它自己的区域访问而不是全局访问.

asp.net-mvc asp.net-mvc-routing asp.net-mvc-areas

5
推荐指数
1
解决办法
1660
查看次数