草庐IT

from_int

全部标签

c# - 通过 ref : cannot convert from 'Foo' to 'ref IFoo' 传递实现

这个问题在这里已经有了答案:Whydoesn't'ref'and'out'supportpolymorphism?(10个答案)关闭3年前。有人可以向我解释为什么这在C#中是不正确的吗:namespaceNamespaceA{publicclassClassA{publicinterfaceIInterfaceA{StringProperty{set;}}}}namespaceNamespaceB{publicclassClassB{publicclassImpA:NamespaceA.ClassA.IInterfaceA{privateStringmProperty;publicSt

c# - 从集合创建 HashSet<int> 的最坏情况复杂度

我收藏了int我用来填充HashSet的值按照以下方式-varhashSet=newHashSet(myIEnumerable);假设迭代IEnumerable是O(n),创建HashSet的最坏情况复杂度是多少?以这种方式? 最佳答案 文档实际上指出:ThisconstructorisanO(n)operation,wherenisthenumberofelementsinthecollectionparameter.http://msdn.microsoft.com/en-us/library/bb301504.aspx

c# - 无效的 URI : The Authority/Host could not be parsed from very long url

这是Youtube视频的实际url,此时如果您复制到您的chrome浏览器,您可以观看该视频。但是,当我尝试创建请求时,我得到了UriFormatException。我做错了什么?HttpWebRequestrequest=(HttpWebRequest)HttpWebRequest.Create(url);http:/r6---sn-x5jjxnn-ogul.googlevideo.com/videoplayback?ratebypass=yes&ms=au&fexp=924615,912522,932260,910207,936330,916611,936117,936910,93

c# - 在 LINQ 中嵌套 'froms'

我是LINQ的新手,我对嵌套from有问题:usingSystem;usingSystem.Linq;classMultipleFroms{staticvoidMain(){char[]chrs={'A','B','C'};char[]chrs2={'X','Y','Z'};varpairs=fromch1inchrsfromch2inchrs2selectch1+""+ch2;Console.WriteLine("ForABCandXYZ:");foreach(varpinpairs)Console.WriteLine(p);Console.WriteLine();Console.W

c# - 被拳击迷惑。将 -1 转换为 Int64 会抛出 InvalidCastException

好吧,我一定是忽略了一些非常简单的东西,但我迷路了。鉴于此objectval=-1;varfoo=(Int32)(val);varbar=(Int64)(val);转换为Int64抛出InvalidCastException。我知道这与拳击的一些奇怪之处有关,但我不明白其中的原因。据我所知,val在第一行被装箱为Int32。然后,当我尝试转换为Int32以外的其他内容时,将抛出InvalidCastException。我想这意味着当它实际上是Int32时,我正试图将val拆箱为Int64?还是很奇怪。不能转换为值拆箱然后尝试执行转换吗?类似的东西(显然这过于简单化了,也许盒装类型是未知

C# 将小数安全地转换为 int

我正在尝试安全地将小数转换为整数。有点像publicstaticboolDecimal.TryConvertToInt32(decimalval,outintval)如果无法转换为整数,则返回false,如果可以,则返回true并成功输出。这是为了避免在decimal.ToInt32方法中捕获OverflowException。最简单的方法是什么? 最佳答案 这里:publicstaticboolTryConvertToInt32(decimalval,outintintval){if(val>int.MaxValue||val

c# - linq-to-sql 使用多个 from 子句语法与传统连接语法进行连接

使用2个from子句和像这样的where编写连接有什么区别:varSomeQuery=fromainMyDC.Table1frombinMyDC.Table2wherea.SomeCol1==SomeParameter&&a.SomeCol2===b.SomeCol1并使用连接运算符编写一个连接。这是针对2个表的join但当然,有时我们需要连接更多的表,我们需要将其他from子句与组合其中如果我们选择上面的语法。我知道这两种语法查询返回相同的数据,但我想知道是否存在性能差异或另一种差异,最终会偏向于一种语法而不是另一种语法。感谢您的建议。 最佳答案

c# - 温莎城堡 : Auto-register types from one assembly that implement interfaces from another

我使用CastleWindsor作为我的IoCcontainer.我有一个具有类似于以下结构的应用程序:MyApp.Services.dllIEmployeeServiceIContractHoursService...MyApp.ServicesImpl.dll员工服务:MyApp.Services.IEmployeeServiceContractHoursService:MyApp.Services.IContractHoursService...我使用XMLconfiguration目前,每次我添加一个新的IService/Service对时,我都必须向XML配置文件添加一个新组

c# - 为什么 <enum> 的集合无法转换为 <int?>?

为什么enum的集合无法转换为int?enumTest{A=1,B=2};int?x=(int?)Test.A;//Validvarcollection1=new[]{Test.A}.Cast().ToList();//InvalidCastExceptionhasthrown(Specifiedcastisnotvalid.)varcollection2=new[]{Test.A}.Cast().ToList(); 最佳答案 Cast方法只能进行装箱/拆箱转换、引用转换以及枚举类型与其基础整数类型之间的转换。不过,拆箱必须是正确的

c# - LINQ to Entities 无法识别方法 'Int32 IndexOf(System.String, System.StringComparison)' 方法

我已经使用Entityframework执行了一个linq查询,如下所示GroupMastergetGroup=null;getGroup=DataContext.Groups.FirstOrDefault(item=>keyword.IndexOf(item.Keywords,StringComparison.OrdinalIgnoreCase)>=0&&item.IsEnabled)执行此方法时出现如下异常LINQtoEntitiesdoesnotrecognizethemethod'Int32IndexOf(System.String,System.StringCompariso