Tag: 数组

C#params object 奇怪的行为

考虑这个代码 namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] strings = new string[] { “Test1”, “Test2”, “Test3” }; int[] ints = new int[] { 1, 2, 3, 4 }; Test(strings); Test(ints); } public static void Test(params object[] objects) { } } } 这个页面https://msdn.microsoft.com/fr-ca/library/w5zay9db.aspx 我希望(params object []对象)是一个元素的数组,以字符串[]作为第一个元素,但是当我调试时,我看到(params object []对象)是{“Test1”,“Test2” “,”Test3“}。 但是,使用int [],我得到一个object […]

向上移动/移动对象然后将第一个元素移动到最后一个索引

我正在Unity3D中构建一个游戏,我试图通过启用和禁用它们而不是实例化和销毁它们来重用GameObjects。 我在GameObject数组中有10个弹簧,每次我使用弹簧时我想从数组中的第一个元素中取出它,将该数组的所有剩余元素移位,然后将第一个Object移动到最后一个索引中。arrays。

C#中两个数组的相关性

有两个double值数组,我想计算相关系数(单个double值,就像MS Excel中的CORREL函数一样)。 C#中有一些简单的单行解决方案吗? 我已经发现了名为Meta Numerics的数学库。 根据这个问题 ,它应该做的工作。 这是Meta Numerics相关方法的文档,我没有得到。 可以请某人为我提供简单的代码片段或示例如何使用该库? 注意:最后,我被迫使用一种自定义实现。 但是,如果有人在阅读这个问题时知道好的,有文档记录的C#数学库/框架,请不要犹豫,并在回答中发布一个链接。

C#不安全值类型数组到字节数组转换

我使用扩展方法将float数组转换为字节数组: public static unsafe byte[] ToByteArray(this float[] floatArray, int count) { int arrayLength = floatArray.Length > count ? count : floatArray.Length; byte[] byteArray = new byte[4 * arrayLength]; fixed (float* floatPointer = floatArray) { fixed (byte* bytePointer = byteArray) { float* read = floatPointer; float* write = (float*)bytePointer; for (int i = 0; i < […]

按值和引用传递数组

这些是来自ac#book的例子,我正在阅读这个示例实际上正在做的一点点麻烦,想要一个解释来帮助我进一步了解这里发生的事情。 //creates and initialzes firstArray int[] firstArray = { 1, 2, 3 }; //Copy the reference in variable firstArray and assign it to firstarraycopy int[] firstArrayCopy = firstArray; Console.WriteLine(“Test passing firstArray reference by value”); Console.Write(“\nContents of firstArray ” + “Before calling FirstDouble:\n\t”); //display contents of firstArray with forloop using counter for (int i = 0; […]

整数数组作为Dictionary的键

我希望使用整数数组作为键的字典,如果整数数组具有相同的值(甚至是不同的对象实例),它们将被视为相同的键。 我该怎么办? 以下代码不起作用,因为b是不同的对象实例。 int[] a = new int[] { 1, 2, 3 }; int[] b = new int[] { 1, 2, 3 }; Dictionary dic = new Dictionary(); dic.Add(a, “haha”); string output = dic[b];

排序文件夹名称数组,如Windows资源管理器(数字和字母) – VB.NET

我正在自杀并脱水试图让这个数组排序。 我有一个包含生成目录的数组; Dim Folders()As String = Directory.GetDirectories(RootPath) 我需要对它们进行排序,以便它们在win7 / vista中的Windows资源管理器中显示。 – 文件夹名称的数字和字母顺序。 文件夹名称包含字母和数字,有时仅包含字母或仅包含数字。 简单的Array.Sort(文件夹)结果 C:\inetpub\wwwroot\rootpath\1 C:\inetpub\wwwroot\rootpath\10 C:\inetpub\wwwroot\rootpath\100 C:\inetpub\wwwroot\rootpath\1004 C:\inetpub\wwwroot\rootpath\101 C:\inetpub\wwwroot\rootpath\11 C:\inetpub\wwwroot\rootpath\12 C:\inetpub\wwwroot\rootpath\2 C:\inetpub\wwwroot\rootpath\3 C:\inetpub\wwwroot\rootpath\4 C:\inetpub\wwwroot\rootpath\5 C:\inetpub\wwwroot\rootpath\6 C:\inetpub\wwwroot\rootpath\7 C:\inetpub\wwwroot\rootpath\8 C:\inetpub\wwwroot\rootpath\87skjnd C:\inetpub\wwwroot\rootpath\89sdf93kmw3 C:\inetpub\wwwroot\rootpath\9 C:\inetpub\wwwroot\rootpath\ad C:\inetpub\wwwroot\rootpath\bin C:\inetpub\wwwroot\rootpath\dark C:\inetpub\wwwroot\rootpath\erk C:\inetpub\wwwroot\rootpath\jkh23978yoaslkd3 C:\inetpub\wwwroot\rootpath\lk2309as C:\inetpub\wwwroot\rootpath\work C:\inetpub\wwwroot\rootpath\zone 我想拥有的(以及Windows资源管理器显示的内容)是…… C:\inetpub\wwwroot\rootpath\1 C:\inetpub\wwwroot\rootpath\2 C:\inetpub\wwwroot\rootpath\3 C:\inetpub\wwwroot\rootpath\4 C:\inetpub\wwwroot\rootpath\5 C:\inetpub\wwwroot\rootpath\6 C:\inetpub\wwwroot\rootpath\7 C:\inetpub\wwwroot\rootpath\8 C:\inetpub\wwwroot\rootpath\9 C:\inetpub\wwwroot\rootpath\10 C:\inetpub\wwwroot\rootpath\11 C:\inetpub\wwwroot\rootpath\12 C:\inetpub\wwwroot\rootpath\87skjnd C:\inetpub\wwwroot\rootpath\89sdf93kmw3 C:\inetpub\wwwroot\rootpath\100 […]

P / Invoke 属性是否可选用于编组数组?

假设存在一个带有纯C接口的本机函数,如下所示,从本机DLL导出: // NativeDll.cpp extern “C” void __stdcall FillArray( int fillValue, int count, int* data) { // Assume parameters are OK… // Fill the array for (int i = 0; i < count; i++) { data[i] = fillValue; } } 以下P / Invoke工作正常(使用VS2010 SP1测试): [DllImport(“NativeDll.dll”, CallingConvention=CallingConvention.StdCall)] public static extern void FillArray( int fillValue, int count, [In, […]

C#中的随机数生成器 – 唯一值

我正忙着在C#中编写一个数组。 我可以用随机生成器来填充它,但现在我的问题是如何做到这一点,但我可以检查数值是否已经在数组中,如果是这样,生成一个新的值 额外信息: 最大值:100 要素数量:100 重要的PLZ工作继续我的想法 我的想法 public void FillArray(int[] A, int Range) { for (int I = 0; I < A.Length; I++) { A[I] = ValidNumber(T, I, Range); } } /* Fill Array */ 实施选择排序 public void SelectionSort(int[] A) { int K, X; for (int I = 0; I < A.Length – 1; I++) […]

整数数组的C#哈希码

我有一个类,内部只是一个整数数组。 一旦构造,arrays永远不会改变。 我想预先计算一个好的哈希码,以便这个类可以非常有效地用作词典中的键。 数组的长度小于约30项,并且整数通常在-1000和1000之间。