草庐IT

non-array

全部标签

c# - Lazy<T> 延迟加载错误 : A field initializer cannot reference the non-static field, 方法或属性

我第一次尝试使用延迟加载来初始化我的类中的进度对象。但是,我收到以下错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.privateLazym_progress=newLazy(()=>{longtotalBytes=m_transferManager.TotalSize();returnnewProgress(totalBytes);});在.NET2.0中,我可以执行以下操作,但我更愿意使用更新的方法:privateProgressm_progress;privateProgressPro

c# - LINQ to SQL insert-if-non-existent

我想知道是否有更简单的方法来插入表中尚不存在的记录。我仍在努力培养我的LINQtoSQL技能。这是我得到的,但似乎应该有更简单的方法。publicstaticTEntityInsertIfNotExists(DataContextdb,Tabletable,Funcwhere,TEntityrecord)whereTEntity:class{TEntityexisting=table.SingleOrDefault(where);if(existing!=null){returnexisting;}else{table.InsertOnSubmit(record);//Can'tuse

c# - System.Array 背后的 secret

我们知道System.Array是一个抽象类,不管DataType[]我们使用运行时以某种方式为我们创建了一些具体的实现(尽管很模糊)。考虑以下代码段。int[]someInts={1,2,3,4};IListcollection=someInts;collection.Clear();collection.Clear()抛出NotSupportedException,那里没有什么奇怪的。当我查看“StackTrace”时,我惊讶地发现它显示了一些奇怪的“类型”SZArrayHelper在调用堆栈的顶部。堆栈跟踪:atSystem.SZArrayHelper.Clear[T]()//N

c# - 为什么 C# Array.BinarySearch 这么快?

我在C#中实现了一个非常简单的binarySearch实现,用于在整数数组中查找整数:二分查找staticintbinarySearch(int[]arr,inti){intlow=0,high=arr.Length-1,mid;while(lowarr[mid])low=mid+1;elsereturnmid;}return-1;}将它与C#的原生Array.BinarySearch()进行比较时,我可以看到Array.BinarySearch()快两倍以上作为我的功能,每一次。MSDNArray.BinarySearch:Searchesanentireone-dimensiona

c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge

c# - C# : generate a list of two dimension arrays with the same shape 中的 FsCheck

假设我正在编写一些视频分析代码。这是视频类的简化版本:publicclassVideo{publicreadonlyintWidth;publicreadonlyintHeight;publicreadonlyListFrames;publicVideo(intwidth,intheight,IEnumerableframes){Width=width;Height=height;Frames=newList();foreach(varframeinframes){if(frame.GetLength(0)!=height||frame.GetLength(1)!=width){thr

C#:Array.CreateInstance:无法将类型 [*] 的对象转换为类型 []

我想通过调用在c#中创建一个非零下界一维数组Array.CreateInstance(typeof(int),newint[]{length},newint[]{lower});返回数组的类型不是int[],而是int[*]。谁能详细说明这是什么意思?我希望能够将这个数组返回给调用者,例如,int[]GetArray(){...}谢谢。 最佳答案 是的,这是一个陷阱!向量和一维数组之间存在差异。int[]是一个向量。向量(如int[])必须从0开始。否则,您必须将其命名为Array。例如://andyes,thisisdoingit

c# - Array.Copy 在 C# 中是如何实现的?

我尝试使用ILSpy在C#中查看Array.Copy的实现,但它没有向我展示实现本身。我写了一个简单的基准测试,Array.Copy与一个简单的for循环来复制数据。Array.Copy更快。如何更快地实现?谢谢,谢伊 最佳答案 反汇编Array类将使您得到这个声明:[MethodImpl(MethodImplOptions.InternalCall),SecurityCritical,ReliabilityContract(Consistency.MayCorruptInstance,Cer.MayFail)]internalst

c# - Parallel.Foreach 给出错误 "Index was outside the bounds of the array "

我在parallel.foreach中遇到了一些问题,即“索引超出了数组的范围”。我附上了parallel.foreach的一些代码以及崩溃的地方。varlstFRItems=session.CreateCriteria().Add(Restrictions.Eq("TSCEnterprise.FEnterpriseID",EnterpriseId)).AddOrder(Order.Asc("FName")).List();ListlstItemAccount=newList();varListAccounts=session.CreateCriteria().List();//lst

c# - 隐式类型数组 : why we can't set array size explicitly?

C#语言规范(7.6.10.4)说,数组创建表达式有树种:newnon-array-type[expression-list]rank-specifiersoptarray-initializeroptnewarray-typearray-initializernewrank-specifierarray-initializer第三个用于隐式类型数组:varfoo=new[]{1,2,3};问题:在隐式类型数组的情况下,是否有任何重要的理由禁止显式设置数组大小?与这种语法相比,它看起来像是不对称行为:varfoo=newint[3]{1,2,3};更新。稍微澄清一下。我可以看到,显式设