Tag: arrays

在尝试启动多个线程时,索引超出了数组的范围

我有这个代码,它给了我一个“索引超出了数组的范围”。 我不知道为什么会发生这种情况,因为变量i应该总是小于数组bla的长度,因此不会导致此错误。 private void buttonDoSomething_Click(object sender, EventArgs e) { List t = new List(); string[] bla = textBoxBla.Lines; for (int i = 0; i some_thread_funmction(bla[i]))); t[i].Start(); } } 有人能告诉我如何解决这个问题,为什么会发生这种情况。 谢谢!

MS Charts C#DataSource from array or List

我想从二维数组中的值填充图表的数据,一列将呈现X轴,第二列呈现Y轴..我做了它,但它不是从数组读取,它给出我运行应用程序时的默认行,我发现使用List 的解决方案,我有一个错误,所以如果任何人可以帮助我,我会感激:D 这是代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ICS381Project { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { int[,] AndFunction = { { 0, 0, 0 }, { 0, 1, 0 }, […]

C#中的隐式数组转换

我有以下类定义了隐式转换运算符: class A { … } class B { private A m_a; public B(A a) { this.m_a = a; } public static implicit operator B(A a) { return new B(a); } } 现在,我可以隐含地将A转换为B. 但为什么我不能隐含地将A []强制转换为B []? static void Main(string[] args) { // compiles A a = new A(); B b = a; // doesn’t compile […]

C#Byte 到BCD,BCD到INT

我有一个由CashRegister Machine创建的Hex文件。 我必须阅读此文件。 文件使用下面详述的格式。 它就像套接字数据包。 代码数据:2个字节 PLU代码数据:7字节 单价数据:5字节 数量数据:5个字节 总金额数据:5字节 PLU名称数据:18字节 税率数据:1字节 长度:24 + 19 Byte PLU代码格式是BCD 单价1-9999999999(BCD) 数量1-9999999999(BCD最后3个数字应为十进制) 总金额1-9999999999(BCD) 我用二进制读取器读取hex文件,然后在Unit Price字节数组中插入int。 byte[] bytes = { data[21], data[22], data[23], data[24], data[25] }; // BCD Byte Array 这个数组是单价。 但是,如何将此数字转换为十进制数。 并且信息说数量:BCD最后一个数字应该是十进制 – 这是什么意思? 谢谢。

将Json数组解析为c#中的类

我解析了这个单独的Json: { “text”: “Sample Text”, “id”: 123456789, “user”: { “name”: “ExampleUser”, “id”: 123, “screen_name”: “ExampleUser” }, “in_reply_to_screen_name”: null, } 到我的c#class RootObject: public class User { public string name { get; set; } public int id { get; set; } public string screen_name { get; set; } } public class RootObject { public string text { […]

固定大小的结构类型数组

如何在C#中声明结构类型的固定大小数组: [StructLayout(LayoutKind.Sequential,Pack=1), Serializable] public unsafe struct MyStruct{ … } public class MyClass { … public fixed MyStruct myStruct[256]; } 这将导致CS1663:不允许使用结构类型的固定大小缓冲区,我该如何解决这个问题?我不喜欢使用C#或“托管集合数据结构”类型,因为我需要经常将其编译为本机C ++

在c#中将单维数组转换为2D数组

我有两个1Darrays。 我想将这两个数组转换为单个2D数组。 我的代码是: public Static void Main() { int[] arrayRow; int[] arrayCol; for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { int[,] myArray = new int[row,column]; myArray[i,j] = arrayRow[i]; // not possible — your suggestions } } for (int i = 0; i < […]

将固定大小数组的C ++结构编组到C#中

我有一个C#struct声明如下: public struct AdvertisementData { public byte SomeId; [MarshalAs(UnmanagedType.LPArray , SizeConst = 12)] public byte[] AnArray; } 它是C ++的对应物: struct AdvertisementData { uint8_t SomeId; uint8_t AnArray[12]; }; 当我尝试将上述结构的堆栈分配实例的引用从C ++发送到C#时,我得到:“Byte []类型的结构字段不能作为LPArray编组。” 知道我做错了什么吗?

从C#中的字符串数组中获取随机值的最快方法?

在.net 2.0框架中从C#中的字符串数组中获取随机值的最快方法是什么? 我想他们可能有这个: string[] fileLines = File.ReadAllLines(filePath); fileLines.GetRandomValue(); 是的,我知道GetRandomValue()不是一个实际的方法,是否有类似的东西或多或少同样短而甜?

使用Newtonsoft将JSON数组数组反序列化为List of Tuples

我从在线服务提供商处收到的数据如下: { name: “test data”, data: [ [ “2017-05-31”, 2388.33 ], [ “2017-04-30”, 2358.84 ], [ “2017-03-31”, 2366.82 ], [ “2017-02-28”, 2329.91 ] ], } 我想将它解析成一个看起来像这样的对象: public class TestData { public string Name; public List<Tuple> Data; } 我唯一能找到的是如何将一组对象解析成一个tulples列表,例如: Json.NET反序列化其他类型中的Tuple 不起作用? 有没有办法编写一个可以处理这个问题的自定义转换器?