草庐IT

ref-link-section-d

全部标签

c# - 检查文件是真实的还是符号链接(symbolic link)

有没有办法使用C#判断文件是真实文件还是符号链接(symboliclink)?我已经挖掘了MSDNW32docs,并且找不到任何东西来检查这个。我在这里使用CreateSymbolicLink,它工作正常。 最佳答案 privateboolIsSymbolic(stringpath){FileInfopathInfo=newFileInfo(path);returnpathInfo.Attributes.HasFlag(FileAttributes.ReparsePoint);} 关于c

c# - 无法在扩展方法中对第一个 ("this") 参数使用 ref 和 out?

为什么禁止使用ref修饰符调用ExtensionMethod?这是可能的:publicstaticvoidChange(refTestClasstestClass,TestClasstestClass2){testClass=testClass2;}而这个不是:publicstaticvoidChangeWithExtensionMethod(thisrefTestClasstestClass,TestClasstestClass2){testClass=testClass2;}但为什么呢? 最佳答案 您必须明确指定ref和out。

c# - 是否可以将属性作为 "out"或 "ref"参数传递?

如果不能,我可以将属性作为“out”或“ref”参数传递吗?为什么不呢?例如Personp=newPerson();...publicvoidTest(outp.Name); 最佳答案 很抱歉回答很简短,但是不行,C#语言规范不允许这样做。查看此answer到另一个问题,看看当你尝试时会发生什么。它还说明了为什么您不应该将该属性设置为公共(public)字段来绕过限制。希望对你有帮助编辑:你问为什么?您将变量传递给out或ref参数,您实际上传递的是变量的地址(或内存中的位置)。在函数内部,编译器知道变量的实际位置,并获取值并将值写

C#:如何将 null 传递给需要 ref 的函数?

我有以下功能:publicstaticexternuintFILES_GetMemoryMapping([MarshalAs(UnmanagedType.LPStr)]stringpPathFile,outushortSize,[MarshalAs(UnmanagedType.LPStr)]stringMapName,outushortPacketSize,refMappingoMapping,outbytePagesPerSector);我想这样调用它:FILES_GetMemoryMapping(MapFile,outsize,MapName,outPacketSize,null,

c# - System.IO.Exception 错误 : "The requested operation cannot be performed on a file with a user-mapped section open."

我在写入XML文件时收到一个非常奇怪的IOException:System.IO.IOException:Therequestedoperationcannotbeperformedonafilewithauser-mappedsectionopen.atSystem.IO.__Error.WinIOError(Int32errorCode,StringmaybeFullPath)atSystem.IO.FileStream.Init(Stringpath,FileModemode,FileAccessaccess,Int32rights,BooleanuseRights,FileSh

C# ref 是像 C/C++ 中的指针还是 C++ 中的引用?

我正在使用ref并且没有清楚地理解“它是像C/C++中的指针还是像C++中的引用?”为什么我问了你一时想的这么弱的问题?因为,当我阅读C#/.NET书籍、msdn或与C#开发人员交谈时,我会因以下原因而感到困惑:C#开发人员建议不要在函数的参数中使用ref,例如...(refTypesomeObject)对他们来说闻起来不好,他们建议...(TypesomeObject),我真的不清楚这个建议。我听到的原因:最好使用对象的副本,然后将其用作返回值,不要通过引用破坏内存等......我经常听到有关DB连接对象的解释。根据我的普通C/C++经验,我真的不明白为什么在C#中使用引用是一件坏事

c# - MVC @RenderSection "sections have been defined but have not been rendered"脚本。多级页面时

我正在使用MVCv4。我有一个“_BootstrapLayout”页面,它定义了所有twitterbootstrap等内容,一个定义网站布局、导航栏等的主页,以及从主页继承的网站页面。_BootstrapLayout.cshtml_MainPage.cshtml@{Layout="~/Views/Shared/_BootstrapLayout.cshtml";}Index.cshtml@{Layout="~/Views/Shared/_MainPage.cshtml";}所以母版页-->主页-->站点页面_BootstrapLayout页面包含脚本的呈现部分@RenderSection

c# - 为什么迭代器方法不能采用 'ref' 或 'out' 参数?

我今天早些时候试过这个:publicinterfaceIFoo{IEnumerableGetItems_A(refintsomethingElse);IEnumerableGetItems_B(refintsomethingElse);}publicclassBar:IFoo{publicIEnumerableGetItems_A(refintsomethingElse){//Ok...}publicIEnumerableGetItems_B(refintsomethingElse){yieldreturn7;//CS1623:Iteratorscannothavereforoutpa

c# - 服务器违反了协议(protocol)。 Section=ResponseHeader Detail=CR 必须跟在 LF 之后,在 WinForms 中?

我正在尝试使用WebClient/HttpWebRequest从服务器下载一些数据。我使用以下代码来执行此操作:WebClientclient=newWebClient();client.Credentials=newNetworkCredential("admin","password");Streamdatastream=client.OpenRead("http://routerlogin.com/cgi-bin/CF_logs.html");StreamReaderreader=newStreamReader(datastream);服务器是我的页面,在我的路由器配置中。它在浏

C#属性和ref参数,为什么不加糖?

我刚刚在使用C#时遇到了这个错误消息Apropertyorindexermaynotbepassedasanoutorrefparameter我知道是什么原因造成的,并快速解决了创建一个正确类型的局部变量,用它作为out/ref参数调用函数,然后将其分配回属性:RefFn(refobj.prop);变成{vart=obj.prop;RefFn(reft);obj.prop=t;}很明显,如果属性在当前上下文中不支持get和set,这将失败。为什么C#不直接为我做这件事?我能想到的唯一可能导致问题的情况是:线程异常(exception)情况对于线程,转换会影响写入发生的时间(在函数调用之