我有错误"对象引用未设置为对象的实例".在下一个方法:
private void alSave_Click(object sender, EventArgs e)
{
_alRecord.WriteXml(@".\alRecord.xml", XmlWriteMode.WriteSchema);
}
Run Code Online (Sandbox Code Playgroud)
我不知道我能做什么...这里是代码:
private string alFile = @".\alRecord.xml";
public DataTable _alRecord;
private DataTable alRecord
{
get
{
if (_alRecord == null)
{
_alRecord = new DataTable();
if (File.Exists(alFile))
{ _alRecord.ReadXml(alFile); }
else
{ InitDataTable2(_alRecord); }
}
return _alRecord;
}
}
private void InitDataTable2(DataTable table)
{
table.TableName = "AlTable";
table.Columns.Add("ID", typeof(int));
table.Columns.Add("sun", typeof(bool));
table.Columns.Add("mon", typeof(bool));
table.Columns.Add("tue", typeof(bool));
table.Columns.Add("wed", typeof(bool));
table.Columns.Add("thu", typeof(bool));
table.Columns.Add("fri", typeof(bool));
table.Columns.Add("sat", typeof(bool));
table.Columns.Add("doors", typeof(string));
table.Columns.Add("from1", typeof(DateTime));
table.Columns.Add("to1", typeof(DateTime));
table.Columns.Add("from2", …Run Code Online (Sandbox Code Playgroud) 如果我有一个线程:
Thread sendMessage = new Thread(new ThreadStart(timer.Start()));
Run Code Online (Sandbox Code Playgroud)
将,计时器的Tick事件将在主线程或sendMessage线程上?
编辑: 我有一个队列,我希望每x毫秒计时器将打勾,程序将队列中的数组出列,但这是我的代码:
Thread sendMessage = new Thread(new ThreadStart(startThreadTimer));
public Queue<Array> messageQueue = new Queue<Array>();
System.Threading.Timer timer;
private void startThreadTimer()
{
System.Threading.TimerCallback cb = new System.Threading.TimerCallback(checkIfQueue);
timer = new System.Threading.Timer(cb, null, 4000, 30);
}
private static void checkIfQueue(object obj)
{
}
Run Code Online (Sandbox Code Playgroud)
我不能调用非静态方法或使用checkIfQueue中的非静态字段,它必须是静态的,我该怎么办?
编辑: 这是你们其中一个人发给我的代码,我给他打电话让它符合我的目标,它会起作用吗?
public ConcurrentQueue<Array> messageQueue = new ConcurrentQueue<Array>();
public void Example()
{
var thread = new Thread(
() =>
{
while (true)
{
Array array;
byte[] byteArray = {};
if (messageQueue.Count …Run Code Online (Sandbox Code Playgroud) 我正在尝试做类似以下的事情:
macro_rules! attr_trial {
($msg:expr) => {{
let id = env!("SOME_ENV");
#[link_section = env!("SOME_ENV")]
static MESSAGE: &'static str = $msg;
}};
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
error: unexpected token: `env`
--> src/main.rs:34:18
|
34 | #[link_section = env!("SOME_ENV")]
| ^
Run Code Online (Sandbox Code Playgroud) 关闭程序的主窗口后,该过程仍在后台运行.如何查看这个奇怪问题的原因是什么?
(我不知道我的程序代码的哪一部分是相关的)
我有一个叫做的类Matrix : IEnumerable<double>,(经典的,数学矩阵.它基本上是一个带有一些好东西的2D数组).
该类是不可变的,因此在创建实例后无法更改其值.
如果想要创建一个具有预先存在的值的矩阵,我必须将数组传递给构造函数,如下所示:
double[,] arr = new double[,]
{
{1,2,3}, {4,5,6}, {7,8,9}
};
Matrix m = new Matrix(arr);
Run Code Online (Sandbox Code Playgroud)
有没有办法把它变成这个:(?)
Matrix m = new Matrix
{
{1,2,3}, {4,5,6}, {7,8,9}
};
Run Code Online (Sandbox Code Playgroud)
更新:
发现了一种破解方式,让它发挥作用.我不确定这个解决方案是否可取,但它确实有效.
class Matrix : ICloneable, IEnumerable<double>
{
// Height & Width are initialized in a constructor beforehand.
/*
* Usage:
* var mat = new Matrix(3, 4)
* {
* {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12}
* };
*/
int rowIndex;
bool allowArrayInitializer;
double[,] tempData;
double[,] data;
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个二叉树,但由于某种原因我的代码不起作用.有人能帮帮我吗?我输入随机数,它...我无法解释它,最好自己运行它并在调试中看到结果;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
leaf root = new leaf();
while (true)
{
string read = Console.ReadLine();
if (read == "print")
{
root.print();
}
else
{
root.grow(Convert.ToInt32(Console.ReadLine()));
}
}
}
}
class leaf
{
public void print()
{
}
public void grow(int value)
{
if (isNull)
{
isNull = false;
this.value = value;
smaller = bigger = new leaf();
}
else
{
if (value > …Run Code Online (Sandbox Code Playgroud) 我正在尝试从源代码构建女妖.我跑了autogen.sh,这是(部分)输出:
configure: error: Package requirements (gstreamer-0.10 >= 0.10.26
gstreamer-base-0.10 >= 0.10.26
gstreamer-plugins-base-0.10 >= 0.10.26
gstreamer-controller-0.10 >= 0.10.26
gstreamer-dataprotocol-0.10 >= 0.10.26
gstreamer-fft-0.10 >= 0.10.26) were not met:
No package 'gstreamer-0.10' found
No package 'gstreamer-base-0.10' found
No package 'gstreamer-plugins-base-0.10' found
No package 'gstreamer-controller-0.10' found
No package 'gstreamer-dataprotocol-0.10' found
No package 'gstreamer-fft-0.10' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables GST_CFLAGS
and GST_LIBS to avoid the need …Run Code Online (Sandbox Code Playgroud) 解决:你们是最好的!我把goyouidiot_Click它的内容带到了一个叫做的方法displayResult,然后:
private void t1_TextChanged(object sender, EventArgs e)
{
displayResult();
}
Run Code Online (Sandbox Code Playgroud)
我之前怎么没想到的?大声笑,thx
这是原始的信息:
没有人在前我建立了一个计算15个数字的小软件.单击buttun时代码开始运行,但是我想把这段代码放在一个开始用程序运行的infinate循环中,所以答案将自动更新.这是我的代码:
Run Code Online (Sandbox Code Playgroud)private void goyouidiot_Click(object sender,EventArgs e){....}
那些不理解的人:
我有15个文本框,我希望该方法在文本框的内容发生变化时运行.
c# ×8
.net ×4
banshee ×1
binary-tree ×1
dependencies ×1
loops ×1
macros ×1
mono ×1
rust ×1
wpf ×1