草庐IT

object_property

全部标签

C# 错误 : The call is ambiguous between the following methods or properties. 运算符重载

我在名为Dinero的命名空间中有2个带有重载运算符的类,这些是2个类:第一个:namespaceDinero{classDollar{#regionAtributospublicDoublecant;#endregion#regionConstructorespublicDollar(){this.cant=0;}publicDollar(Doubleamount){this.cant=amount;}#endregion#regionSobrecargadeOperadorespublicstaticDollaroperator+(Euroeu,Dollardol){Dollard

c# - 在 Linq-To-Sql 中避免 "Nullable object must have a value."

我有一个这样的方法查询:publicIListGetBusinessObject(Guid?filterId){using(vardb=newL2SDataContext()){varresult=fromboindb.BusinessObjectswhere(filterId.HasValue)?bo.Filter==filterId.value:trueorderbybo.NameselectSqlModelConverters.ConvertBusinessObject(bo);returnresult.ToList();}}在运行时,这会抛出一个System.InvalidOp

c# - 'Property:NETFRAMEWORK45' 部分中对符号 'Product:*' 的未解决引用

在TFS2010中构建应用程序时出现错误。未解决对“产品:*”部分中符号“属性:NETFRAMEWORK45”的引用。这是用于Wix3.9Wix包引用了NetFxExtension。我可以在我的本地机器上很好地构建wix,但是当我通过TFS构建它时,我得到了错误。谁能帮我解决这个问题?我有以下导致错误的代码。 最佳答案 您必须在您的项目中包含WixNetFxExtension,最多3个位置在wxs文件的Wix元素中,添加命名空间xmlns:netfx="http://schemas.microsoft.com/wix/NetFxEx

c# - 使用 "Expression Bodied Functions and Properties"有什么好处

这个问题在这里已经有了答案:Expression-bodiedfunctionmembersefficiencyandperformanceinC#6.0(2个答案)关闭6年前。我确实看到很多人使用该新功能,但使用这些表达式有什么好处?Examples:publicoverridestringToString()=>string.Format("{0},{1}",First,Second);publicstringText=>string.Format("{0}:{1}-{2}({3})",TimeStamp,Process,Config,User);这个问题不同于thisone,因为

c# - ExecuteScalar 调用抛出异常 "Object reference not set to an instance of an object"

在单元测试中调试以下方法时出现以下错误Objectreferencenotsettoaninstanceofanobject点击以下行时result=(int)validateDatabase.ExecuteScalar();方法是publicstaticBooleanValidate(stringargument1,stringargument2){intresult=-1;using(varconnection=newSqlConnection("connectionstring")){SqlCommandvalidateDatabase=newSqlCommand("PROCED

c# - 为什么我不能将 DateTime[] 转换为 object[]?

看来我可以将DateTime转换为object,那么为什么我不能将数组DateTime[]转换为object[]?我知道这与值/引用类型有关,但装箱不允许我这样做吗? 最佳答案 Arraycovariance仅适用于引用类型的数组。DateTime是一种值类型,因此您不能将DateTime[]分配给object[]变量。您必须显式创建一个对象数组并将值复制过来。换句话说,创建一个类型为object[]的新数组实例。有很多方法可以做到这一点。CopyTo()的简单使用应该足够了。DateTime[]x=newDateTime[]{..

c# - 简单的linq问题: using linq to get an array of properties

假设我们有一个简单的类publicclassFoo{publicstringFooName;}现在我们想对其做一些简单的工作。publicvoidSomeCallerMethod(ListlistOfFoos){string[]fooNames=listOfFoo.//Whattodohere?}如果我什至知道调用什么方法,我可能就能找到其余的部分。 最佳答案 您想将您的类列表转换为字符串数组。理想的方法是Select,它对可枚举对象的每个元素进行操作,并根据您返回的类型构建一个新的可枚举对象。您需要将lambda表达式放入返回名称

c# - Linq to objects - 选择第一个对象

我对linq几乎一无所知。我这样做:varapps=fromappinProcess.GetProcesses()whereapp.ProcessName.Contains("MyAppName")&&app.MainWindowHandle!=IntPtr.Zeroselectapp;这让我获得了符合该条件的所有正在运行的进程。但我不知道如何获得第一个。我在网上找到的例子似乎暗示我必须这样做varmatchedApp=(fromappinProcess.GetProcesses()whereapp.ProcessName.Contains("MyAppName")&&app.Main

c# - LINQ to Entities 无法识别方法 'System.Object GetValue(...)'

我的问题是我需要查询泛型类中属性的值。该属性用属性标记。请看下面的代码:varrowKeyProperty=EFUtil.GetClassPropertyForRowKey();vartenantKeyProperty=EFUtil.GetClassPropertyForTenantKey();varqueryResult=objContext.CreateObjectSet().Single(l=>(((int)tenantKeyProperty.GetValue(l,null))==tenantKey)&&(((int)rowKeyProperty.GetValue(l,null)

c# - 林克到 SQL : Sort Query by Arbitrary Property(Column) Name

我有一个更大/更复杂的问题,但为了简单起见,让我们考虑以下问题:假设我在SQL数据库中有一个名为Product的表,它有两列,ID(int,primary键)和名称(varchar/string)。我还有一个简单的LINQDataContext。我构造了一个查询并将其交给“我的”函数。让我们假设它是这样的:(虽然它可能有点复杂)IQueryablequery=frompindb.Productsselectp;一旦我的方法得到这个查询,作为参数传入,它必须更改排序顺序,例如IQueryablesortedQuery=query.OrderBy(x=>x.Name);我想让它更通用,即指