草庐IT

filter_has_var

全部标签

c# - var 默认为哪种 int 类型?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:C#short/long/intliteralformat?Reading关于var在编程中的使用,我很好奇var在用于int类型时的默认值。例如,如果我使用varfoo=65535类型是ushort还是int?谢谢。

c# - 除了 LINQ,有人发现 "var"的用途吗?

只是好奇。我大约99.999%确定没有...但有什么?编辑:这些都是好的答案(节省打字时间或使代码不那么冗长以提高“可读性”)。我想我应该澄清一下我所说的“使用”是什么意思——一些没有“var”就无法完成的构造/设计。 最佳答案 什么在可读性方面更好?AReallyReallyLongBusinessObjectNameobj=newAReallyReallyLongBusinessObjectName();或varobj=newAReallyReallyLongBusinessObjectName();我说的是可读性,因为使用va

c# - 将类型 'var' 传递给 C# 中的方法

这个问题在这里已经有了答案:HowcanIreturnananonymoustypefromamethod?(4个答案)关闭9年前。我有一些数据类型为var的子查询。这些正在处理数据表。我想将这些传递给另一种方法,我该怎么做?例如:varsubquery1=fromresultsintable.AsEnumerable()where//someconditionselectnew{column1=results.field1,column2=results.field2etc.,}varsubquery2=fromresultsintable.AsEnumerable()where//

c# - C# 中的 var - 为什么它不能用作成员变量?

这个问题在这里已经有了答案:Implicittyping;whyjustlocalvariables?(6个答案)关闭8年前。为什么在C#中不能在类级别拥有隐式类型的变量,因为当这些变量被立即赋值时?即:publicclassTheClass{privatevaraList=newList();}这只是尚未实现的事情,还是存在未实现的概念/技术原因?

c# - 如何在没有 "process has exited"异常的情况下终止进程?

我使用Process.Kill()来终止进程。像这样:if(!process.WaitForExit(5000)){process.Kill();}有时进程会在两行之间退出,所以控制会进入if然后Kill会产生异常:System.InvalidOperationExceptionCannotprocessrequestbecausetheprocess(ProcessIdHere)hasexited.atSystem.Diagnostics.Process.GetProcessHandle(Int32access,BooleanthrowIfExited)atSystem.Diagno

c# - "Service X has zero application endpoints"除非我在代码中添加端点 - 为什么?

我关注了thisMSDNarticle彻底创建托管在托管NT服务中的WCF服务。当我在服务控制台中单击“开始”时,我会在事件查看器中看到以下内容:Servicecannotbestarted.System.InvalidOperationException:Service'MyServiceNamespace.RequestProcessorImpl'haszeroapplication(non-infrastructure)endpoints.Thismightbebecausenoconfigurationfilewasfoundforyourapplication,orbecau

c# - linq-to-sql "Cannot remove an entity that has not been attached"

当我尝试删除记录时出现错误Cannotremoveanentitythathasnotbeenattached.。我四处搜索,虽然有很多地方可以找到解决这个问题的方法,但建议的修复方法并没有让我更进一步:using(MyDataContextTheDC=newMyDataContext()){TheDC.MyTable.Attach(ARecord);//addedthislinebutdoesn'tfixit.TheDC.MyTable.DeleteOnSubmit(ARecord);TheDC.SubmitChanges();我更大的问题是:这个问题只影响删除查询还是影响其他类型的

c# - AngularJS 与 Asp.net Web API : $http post returning XMLHttpRequest cannot load: Response for preflight has invalid HTTP status code 405

当尝试使用$http将jsonPOST到Asp.netwebAPI服务器时,它返回以下错误XMLHttpRequestcannotloadhttp://localhost:62158/api/video/add.ResponseforpreflighthasinvalidHTTPstatuscode405但是从$.ajax发出相同的请求是工作文件。$HTTP代码$http.post(url,data,config).success(function(data,status,headers,config){defered.resolve(data);}).error(function(d

c# - "StandardOut has not been redirected or the process hasn' t started yet”在 C# 中读取控制台命令输出时

感谢@user2526830提供的代码。基于该代码,我在程序中添加了几行,因为我想读取SSH命令的输出。下面是我的代码,它在while行出错StandardOuthasnotbeenredirectedortheprocesshasn'tstartedyet.我想要实现的是,我想将ls的输出读入一个字符串。ProcessStartInfostartinfo=newProcessStartInfo();startinfo.FileName=@"f:\plink.exe";startinfo.Arguments="-sshabc@x.x.x.x-pwabc123";Processproce

c# - var 关键字并不总是有效?

C#,VS2010。有人,请解释为什么我不能在下面的代码中使用var!varprops=TypeDescriptor.GetProperties(adapter);//errorCS1061:'object'doesnotcontainadefinitionfor'DisplayName'foreach(varpropinprops){stringname=prop.DisplayName;}//Noerrorforeach(PropertyDescriptorpropinprops){stringname=prop.DisplayName;}TypeDescriptor.GetPro