【c# – FxCop说我应该返回一个通用列表接口而不是字节数组.我是不是该?】教程文章相关的互联网学习教程文章

c#-每个N元素的新数组【代码】

我有200个元素组成的数组,并且我试图通过对每N个元素进行处理将其拆分成较小的数组,这意味着我无法使用.take / .skip命令,我目前已经尝试了不同的解决方案如: 一个Parallel.for和parallel.foreach(如果我能弄清楚那将是最好的) 并具有正常的for和foreach循环,但此刻停滞不前,我所能做的就是自己创建一个新组的静态解决方案,以解决arrEtiket中N个元素的数量string[] arrEtikets = Directory.GetFiles("");public string[] Group2()...

从数组列表C#中排除项目【代码】

我正在使用ASP.NET 2013,我想绘制图表并为每个点指定不同的颜色,除了一些例如黑色,透明等. 它工作正常,但有些颜色我要排除.var colours = typeof(System.Drawing.Color).GetProperties().Where(x => x.PropertyType == typeof(System.Drawing.Color)).Select(x => x.Name).ToArray();Random rColor = new Random();foreach (var item in Chart2.Series[0].Points) {item.Color = System.Drawing.Color.FromName(colours[rColor.Nex...

c#-通过AJAX将数组传递给Controller Action【代码】

我看到了类似的问题,但没有一个帮助我.我有最简单的代码:public JsonResult JsonGetStatesInfo(object[] instructions){if (Request.IsAjaxRequest()){return Json(String.Empty);}elsethrow new NoAjaxRequestException();}和客户端:var instructions = [];instructions.push('abc');instructions.push('ddd');instructions.push('assdbc');var inst = JSON.stringify(instructions);$.ajax({cache: false,data: { 'instruction...

如何获取3维数组C#的横截面【代码】

假设您在C#中有一个3维数组int space[width, height, depth];并且您想实现该方法public int[,] GetCrossSection(int position, int dimension)其中“位置”是沿“维度”指定的要提取切片的点.重要的是不要使用我们仅处理3维的事实,在下面的示例中,您可以通过添加if语句来修复它们,并假设矩阵不会超过3维. 我的第一次尝试(有问题的地方):public int[,] GetCrossSection(int position, int dimension) {int[] dimensionIterationInt...

通过ADS.Net将数组从C#发送到TwinCat 3【代码】

我想使用TwinCat 3来控制阀门并使用Visual Studio C#来处理要显示在喷泉上的图像,从而制作一个自动化的图形喷泉. 图像处理程序的最终形式是二进制数组图像(附加):Image Processing Result 1;Image Processing Result 2; 我想使用图像处理的最终形式来控制机器上的阀门(阀门在1时打开,阀门在0时关闭).我对TwinCat 3感到非常陌生,尤其是ADS图书馆. infosys beckhoff的示例对我没有帮助,有人可以帮助我吗? 谢谢解决方法:我制作了一...

C#练习题答案: 性能#3 - 填写一个Int-数组矩阵 - 极品飞车最高【难度:2级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战【代码】

性能#3 - 填写一个Int-数组矩阵 - 极品飞车最高【难度:2级】: 答案1: using System; using System.Linq;public static class Kata {private static int[] cache = Enumerable.Range(0,4000000).ToArray();public static int[] Performance() => cache; }? 答案2: using System; using System.Linq;public static class Kata {static Kata(){array = new int[4000000];for(int i=0;i<4000000;i++){array[i] = i;}}private static i...

C#-PACT .NET使用者测试:灵活的长度数组【代码】

我正在使用pactNet来测试API,该API应该返回灵活长度的数组. 如果我叫“ myApi / items /”,它应该返回消费者不知道确切尺寸的物品清单.因此答案应如下所示:[{"id": "1","description": "foo"},{"id": "2","description": "foo2"},{"id": "3","description": "foo3"}]或这个:[{"id": "4","description": "foo4"},{"id": "2","description": "foo2"}]如何为此互动创建合同? 在documentation中,是Ruby中的一个示例,但是我在C#中找不...

c#-检查元素索引是否在2d数组内(用于向任意方向移动一个)【代码】

我有这个二维数组的对象private Cell[,] mapCells = new Cell[10, 10];我想检查数组中是否存在坐标为x = m和y = n的键值对. 我为此bool cellExists = index.x >= 0 && // check leftindex.y >= 0 && // check bottomindex.x < mapCells.GetLength(0) && // check rightindex.y < mapCells.GetLength(1); // check top因此,使用此布尔值,我检查单元格是在地图上还是在外部. 有没有更优雅的方法来检查这一点? 编辑: 当检查这个时,我...

c#-仅将“ new”应用于多维数组的一维吗?【代码】

我有这个C#程序,它具有以下代码:/*10 data for one peprson */ private int[] data = new int[10]; private void SomeMethod() { /*More code*/this.data = new int[10];/*More code*/ }当事件发生时,此程序将调用此方法,并且每次发生时,此一维数组都会获取大小为10的数组的“新”实例,并刷新该数组.有点喜欢重置它. 现在,我被告知要编写一个执行相同操作的新程序,只是现在有5个人.所以我创建了一个二维数组private int[,] data...

c#-将字符串数组转换为if else条件的字符串【代码】

我正在尝试学习,(我是编码新手) 我写了这个static void Main(string[] args) {string username = "James";string[] Userclass = new string[3] { "Mage", "Warrior", "Assasin" };Console.WriteLine("What class will you be? You can choose from Mage, Warrior, Or Assasin: ");if (Userclass.Contains("Mage")){String Message = "You are a strong Willed Mage " + username;Console.WriteLine(Message);}if (Userclass.Contai...

C#将二维数组分批处理【代码】

我有一个二维的object [,]数组,其中包含行和列的矩阵(object [nRows,nColumns]). 我想将其分块为一批行-例如我可以枚举成批的1,000行. 总而言之,我正在寻找能执行以下操作但针对二维数组(source)的C#代码:private IEnumerable<T[]> SplitArray<T>(T[] sourceArray, int rangeLength) {int startIndex = 0;do{T[] range = new T[Math.Min(rangeLength, sourceArray.Length - startIndex)];Array.Copy(sourceArray, startIndex, ran...

C#中的多维数组【代码】

我在C#中定义了此多维数组:int[,] values = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } };现在,值不再以这种形式出现,而是在Dictionary中:values2.Add("KeyA", new List<float> {1,4}); values2.Add("KeyB", new List<float> {2,5}); values2.Add("KeyC", new List<float> {3,6});现在,我尝试再次在二维数组中解析此字典,但是不知何故存在问题:List<float> outList = new List<float>(); values2.TryGetValue(values2.Keys.Element...

c#-定长位数组的数组【代码】

我遇到了BitArray的麻烦. 目标是模拟8个80位BitArray的堆栈,编号为0到7. 我只需要能够通过索引访问它们,因此我认为一个简单的数组就足够了. 初始化BitArray对象时,我需要指定它将包含的位数,这使我BitArray test = new BitArray(80);在知道需要指定长度值的情况下,如何对其进行数组处理? 我已经尝试了几件事,例如BitArray[] stack = new BitArray(80)[];但是当我尝试给它长度时总是会出错… 有什么想法吗? 提前致谢解决方法:不幸...

从C#将结构数组传递到C DLL【代码】

我试图将结构数组传递到C DLL中并遇到问题.我一直在试图解决问题,但无济于事.我可以从C中获取数据,当我尝试使用.NET获取结构数组时,我遇到了问题. C原型是:static __declspec(dllexport) int SocketAPI::api_get_data(int iSize, buffer_node *data); 在我的C#代码中,我将该函数定义为:[DllImport("SocketAPI.dll")] static extern int api_get_data(int iSize, buffer_node[] data);我的Struct是buffer_node,其定义为:[StructL...

C#基础—数组

C#基础之数组1. 数组的定义与初始化一维数组: (1) int [] A = new int[4]{ 0,1,2,3}; (2) int[] B = new int[4/变量]; (3) int[] C = { 1, 2, 3, 4 }; (4) int[] D; D = new int[4] { 1, 2, 3, 4 }; 注意: (1) int [] A 第一个[] 不能有行数限制,要在new里设置。 (2) new 表示的是创建数组并初始化。Int型为0,bool型为false,引用类型为null (3) 如...