我花了半个小时试图得到这个,也许有人可以快速拿出来.
我需要一个匹配一个或两个数字的正则表达式,后跟一个可选的decmial点,后跟一个或两个数字.
例如,它应该完整匹配这些字符串:
3
33
.3
.33
33.3
33.33
并且不匹配在decmial点之前或之后超过2位数的任何内容.
可能重复:
标记界面的目的是什么?
创建一个完全空的界面是不好的做法,例如:
public interface ISomething
{
}
Run Code Online (Sandbox Code Playgroud)
在某种情况下,我希望以不同于其他对象的方式对待某些对象,但我不需要任何新的行为.
我在理解表达式和Funcs如何工作之间的差异时遇到了一些麻烦.有人从以下方法更改方法签名时出现此问题:
public static List<Thing> ThingList(Func<Thing, bool> aWhere)
Run Code Online (Sandbox Code Playgroud)
至
public static List<Thing> ThingList(Expression<Func<Thing, bool>> aWhere)
Run Code Online (Sandbox Code Playgroud)
这打破了我的通话代码.旧的调用代码(有效)看起来像这样:
...
object y = new object();
Func<Thing, bool> whereFunc = (p) => p == y;
things = ThingManager.ThingList(whereFunc);
Run Code Online (Sandbox Code Playgroud)
新代码(不起作用)如下所示:
...
object x = new object();
Expression<Func<Thing, bool>> whereExpr = (p) => p == x;
things = ThingManager.ThingList(whereExpr);
Run Code Online (Sandbox Code Playgroud)
在使用表达式的行上的ThingList(...)内部失败:
var query = (from t in context.Things.Where(aWhere)
...
Run Code Online (Sandbox Code Playgroud)
运行时错误:
Unable to create a constant value of type 'System.Object'. Only primitive types ('such as Int32, String, and Guid') …Run Code Online (Sandbox Code Playgroud) 为了调试我的代码中的问题,我已经声明了以下两个字符串,假设它们是等价的:
String print = "8A9B485ECDC56B6E0FD023D6994A57EEC49B0717";
String newPrint = thumbprint.Trim().Replace(" ", "").ToUpper();
Run Code Online (Sandbox Code Playgroud)
我发现他们不是.太好了,这是我的问题的根源.但是,我正在检查即时窗口中的内容(在声明后面的行)并且不明白发生了什么.这是输出:
print
"8A9B485ECDC56B6E0FD023D6994A57EEC49B0717"
newPrint
"?8A9B485ECDC56B6E0FD023D6994A57EEC49B0717"
String.Compare(print, newPrint);
0
print == newPrint
false
print.Equals(newPrint)
false
Run Code Online (Sandbox Code Playgroud)
是吧?为什么他们不平等?
编辑:
我需要用'thumbprint'作为基础.这是用户输入的字符串.我只是使用'newPrint'作为临时变量来保存修剪/上升值.打印是预期的结果.
我有一个程序,当它耗尽磁盘空间写一个文件时,可能会死亡,我不确定是否是这种情况.
我想运行它看看,但我的测试服务器不会很快耗尽空间.有什么方法可以嘲笑这种行为吗?看起来没有办法在Ubuntu中设置文件夹/文件大小限制,并且设置用户配额将是一个过程(由于获得权限)
有没有一种常见的方法来测试这种情况?
我正在运行Ubuntu 12.04
随机示例:
ConfigurationElementCollection
Run Code Online (Sandbox Code Playgroud)
.Net有很多这些WhateverCollection没有实现的IEnumerable<T>小类,这意味着我不能将Linq用于开箱即用的对象.甚至在Linq之前,你会认为他们会想要使用泛型(我相信它已经在C#2中一直被引入)
似乎我一直遇到这些讨厌的小集合类型.有一些技术原因吗?
当InnerException为null时,这将抛出一个空引用异常.
String s = " inner exception: " + e.InnerException == null ? "None" : e.InnerException.Message;
Run Code Online (Sandbox Code Playgroud)
但这不会:
String s = " inner exception: " + (e.InnerException == null ? "None" : e.InnerException.Message);
Run Code Online (Sandbox Code Playgroud)
以上两种都很好.我无法弄清楚前者试图做什么会导致它进行评估e.InnerException.Message.为什么它们不相同?
我们的团队目前正在集思广益一个产品理念,这个理念在我们的方言中已经存在了几年了.
它很可能是托管在WISC堆栈上的ASP.NET MVC Web应用程序(Windows,IIS,SQL Server,C#)......
理想情况下,我们喜欢跟随类似路线前往雾溪的家伙们使用fogbugz提供托管和"运行服务器"风格的解决方案.
当然,我们希望保持代码和数据库模式几乎完全相同(出于维护目的),因此我们可以一次编译.
因此,拥有"为所有用户提供一个大数据库"似乎会增加开发人员开销,从而保持架构等方面的差异.
我记得在2008年收听了堆栈溢出播客,其中joel spolskey提到他的SQL Server实例有数千个数据库,因为它们为每个用户提供了一个专用数据库,但是SQL Server 2000管理那么多数据库时出现了扩展问题.
所以我的问题是:
如果我们有以下变量声明:
List<int> list = new List(5);
Run Code Online (Sandbox Code Playgroud)
为什么这样:
list.insert(2, 3);
Run Code Online (Sandbox Code Playgroud)
失败,出现以下错误:
Index must be within the bounds of the List.
Run Code Online (Sandbox Code Playgroud)
提供初始尺寸有什么意义?
我正在尝试构建的确切代码:
public interface IMapContainer<out T> where T : MapRoomBase
{
String GetName();
IEnumerable<T> GetRooms();
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:方差无效:类型参数"T"必须在"MapLibrary.IMapContainer.GetRooms()"上无效.'T'是协变的.
我认为这是有效的,因为IEnumerable只返回项目,并且不能添加任何项目.为什么这不安全+有效?
c# ×7
asp.net ×1
covariance ×1
ienumerable ×1
iis ×1
interface ×1
linq ×1
linux ×1
list ×1
regex ×1
sql-server ×1
string ×1
testing ×1