草庐IT

word_count_new

全部标签

C#:在Word中搜索文本并获取结果范围

我可以通过以下方式在Word文件中查找文本:Word.Rangerange=wordApp.ActiveDocument.Content;Word.Findfind=range.Find;find.Text="xxx";find.ClearFormatting();find.Execute(refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmiss

c# - 当 IsEmpty == true 时,为什么 ConcurrentQueue<T>.Count 不返回 0?

我在JamesMichaelHare'sblog上阅读了有关.NET4中新的并发集合类的信息,和pagetalkingaboutConcurrentQueue说:It’sstillrecommended,however,thatforemptychecksyoucallIsEmptyinsteadofcomparingCounttozero.我很好奇-如果有理由使用IsEmpty而不是将Count与0进行比较,为什么该类在执行任何昂贵的计数工作之前不在内部检查IsEmpty并返回0?例如:publicintCount{get{//CheckIsEmptysowecanbailoutqu

c# - new FileInfo(path).Name 与 Path.GetFileName(path)

哪个更好用,为什么?我的意思是这两个命令在哪些方面不同以及如何不同?性能、可读性……newFileInfo(path).Name或Path.GetFileName(path) 最佳答案 因为您不必为使用Path.GetFilename()创建新对象,所以性能会更好。这是两者的比较:代码:Path.GetFileName("G:\\u.png")IL:IL_0000:ldstr"G:\u.png"IL_0005:callSystem.IO.Path.GetFileName代码:newFileInfo("G:\\u.png").Name

c# - 当 new-able 使用 new T(),否则使用 default(T)

我正在研究C#泛型函数。错误时,如果泛型类型可以是new-able,返回newT(),否则返回default(T)。代码如下:privateTFunc(){try{//trytodosomething...}catch(Exceptionexception){if(Tisnew-able)//我知道对于那些使用newT()的人来说,它需要whereT:new()。这个问题是,如何在运行时判断这个? 最佳答案 您只需要检查该类型是否具有无参数构造函数。您可以通过以空类型作为参数调用Type.GetConstructor方法来实现。va

c# - Windows 窗体 : add new line to label if text is too long

我正在使用C#。有时,从Web服务返回的文本(我在标签中显示)太长,会在表单边缘被截断。如果表单不适合标签,是否有简单的方法向标签添加换行符?谢谢 最佳答案 如果您将标签设置为autosize,它会随着您放入其中的任何文本自动增长。为了使其以特定宽度自动换行,您可以设置MaximumSize属性。myLabel.MaximumSize=newSize(100,0);myLabel.AutoSize=true;经过测试并有效。如果您希望始终能够看到数据,可以将Label容器的AutoScroll属性设置为true。

c# - 使用 OpenXML SDK 2.0 将页眉和页脚添加到现有的空 word 文档

我正在尝试将页眉和页脚添加到一个空的word文档中。当将docx更改为zip时,我使用此代码在word/document.xml中添加Header部分。ApplyHeader(doc);publicstaticvoidApplyHeader(WordprocessingDocumentdoc){//Getthemaindocumentpart.MainDocumentPartmainDocPart=doc.MainDocumentPart;//Deletetheexistingheaderparts.mainDocPart.DeleteParts(mainDocPart.HeaderP

c# - dot net 是否有像 IEnumerable 这样带有 Count 属性的接口(interface)?

dotnet是否有像IEnumerable这样带有计数属性的接口(interface)?我知道IList和ICollection等接口(interface)确实提供了Count属性,但似乎这些接口(interface)首先是为可变数据结构设计的,用作只读接口(interface)似乎是事后才想到的——存在IsReadOnly字段和mutators抛出异常当此属性为真时,IMO对此提供了充分的证据。目前我正在使用一个名为IReadOnlyCollection的自定义接口(interface)(请参阅我自己对这篇文章的回答),但我很高兴知道其他替代方法。 最佳答

c# - Entity Framework new transaction is not allowed because there are other threads running in the session,多线程保存

我正在尝试将多线程进程的日志保存在数据库中,但出现以下错误:不允许新事务,因为session中还有其他线程在运行。在每个胎面我都有这个功能:internalboolWriteTrace(IResultresult,stringmessage,bytetype){SPC_SENDING_TRACEtrace=newSPC_SENDING_TRACE(message,Parent.currentLine.CD_LINE,type,Parent.currentUser.FULLNAME,Parent.guid);Context.SPC_SENDING_TRACE.AddObject(trac

c# - 起订量参数 TargetParameterCountException : Parameter count mismatch Exception

以下是我的通用基础存储库界面publicinterfaceIRepository{IQueryableAllIncluding(paramsExpression>[]includeProperties);}我的实体publicclassSdk{publicSdk(){this.Identifier=Guid.NewGuid().ToString();}publicvirtualICollectionAccessibleResources{get;set;}publicstringIdentifier{get;set;}}下面是具体的repopublicinterfaceISdkRepo

c# - 为什么要使用 Create 方法而不是使用 "new"?

有什么优点,什么时候适合使用静态构造函数?publicclassMyClass{protectedMyClass(){}publicstaticMyClassCreate(){returnnewMyClass();}}然后通过创建类的实例MyClassmyClass=MyClass.Create();与仅拥有公共(public)构造函数并使用创建对象相反MyClassmyClass=newMyClass();如果Create方法返回类实现的接口(interface)实例,我可以看到第一种方法很有用……它将强制调用者创建接口(interface)实例而不是特定类型。