小编Max*_*Max的帖子

将arraylist复制到数组时出现c#错误

我的项目中有2个arraylists,list1和list2.(两者都包含9个字符串值,car1,car2,car3等.

我还有一个名为store_numbers的字符串数组,它可以包含52个String元素.现在我想将我的值从list1和list2复制到数组中.通过做 :

  list1.CopyTo(store_numbers,0);
Run Code Online (Sandbox Code Playgroud)

我认为这是我收到错误消息的正确方法

源中至少有一个元素无法转换为目标数组类型

谁知道我怎么能解决这个问题?

谢谢!

c#

0
推荐指数
1
解决办法
3718
查看次数

为什么0.43转换为43?

为什么Cbm充满了43而不是0.43

string strCbm;
decimal Cbm;

strCbm = unConvertedCbm.CustomValue.Replace(".", ",");
Cbm = (Quantity * Decimal.Parse(strCbm));
Run Code Online (Sandbox Code Playgroud)

供您参考:

unConvertedCbm.CustomValue =填充0.43

Quantity =填充1

我将在下面描述这段代码:

  1. 我创建一个字符串和一个小数.
  2. 我替换所有'.' 在CustomValue中带有','.
  3. CustomValue插入到strCbm中,0.43转换为0.43.
  4. Cbm填充数量(1)乘以0.43(转换为小数)

在我看来,Cbm应该是0.43而不是43.

为什么Cbm充满了43而不是0.43?

c# decimal visual-studio

0
推荐指数
1
解决办法
65
查看次数

关闭表单后杀死一个帖子?

我有一个在打开新表单实例时创建的线程.此表单打开时,此线程应始终运行.表单关闭后,它应该死掉.

问题是当我打开同一表单的新实例时,它使用相同的线程.

我正在寻找的正确代码可能是我正在考虑的某个方面......除非这是无效的:

t = new Task(Task.Factory.StartNew(() => totalDistance()));
Run Code Online (Sandbox Code Playgroud)

这是整个代码:方法WindowsFormClosing可能是不必要的,但我没有想法.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace ITS3_Eksamen_F2014_201270810
    {
    public partial class DistanceForm : Form
    {
        Data dat;
        private string name;
        Task t;
        private bool killThread;

        public DistanceForm(Data d, string n)
        {
            dat = d;
            name = n;
            InitializeComponent();
            getDistance(name);
            nameLabel.Text = name;
            t = Task.Factory.StartNew(() => totalDistance());
            killThread = false;
        }

        private void getDistance(string name)
        {
            var …
Run Code Online (Sandbox Code Playgroud)

c# multithreading

0
推荐指数
1
解决办法
91
查看次数

C#超载字节错误

我正在尝试创建一个支持4个参数的函数,但它不起作用.我怎么解决这个问题?谢谢.

private void Byte(byte a, byte b, uint c, byte d)
{
     PS3.SetMemory(a + b * c, new byte[] { d });
}

Byte(0x00f474e3 + 0x3700 * dataGridView1.CurrentRow.Index, new byte[] { 0x03 });
Run Code Online (Sandbox Code Playgroud)

错误:

Error: No overload for 'Byte' method takes two arguments
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
80
查看次数

Thread.IsBackground抛出ThreadStateException

下一段代码抛出一个ThreadStateException:

public void StartListening()
{
     this.isListening = true;
     if (!this.listeningThread.IsAlive)
         this.listeningThread = new Thread(ListenForClients);
     this.listeningThread.Start();
     this.listeningThread.IsBackground = true;
}
Run Code Online (Sandbox Code Playgroud)

并设置IsBackground属性

this.listeningThread.IsBackground = true;
Run Code Online (Sandbox Code Playgroud)

抛出异常.

怎么了?我在错误的地方使用IsBackground = true吗?

例外文字:

线程死了; 国家无法访问.
at System.Threading.Thread.SetBackgroundNative(Boolean isBackground
)
at My Systemspace.MyClass.StartListening()的System.Threading.Thread.set_IsBackgrounf(布尔值)
...

IsBackground属性仅在一个地方设置,此处.因此,它在线程工作期间永远不会改变.不幸的是我不能重现这个(仅在客户的系统上复制),所以我不知道原因.这就是我要问的原因.

c# multithreading thread-exceptions

0
推荐指数
1
解决办法
1484
查看次数

IEnumerable.Average()导致错误或是简单的数学?

static void Main(string[] args)
{
    var list = new List<double>() { 115.76000213623, 118.470001220703, 116.049995422363, 115.76000213623, 118.470001220703, 116.049995422363 };

    var avg1 = list.Average();
    HashSet<double> hash = new HashSet<double>();

    foreach(var m in list)
        hash.Add(m);

    var avg2 = hash.Average();
}
Run Code Online (Sandbox Code Playgroud)

我有一个双重列表,范围从10,000到10,000,000.在我的应用程序的特定阶段,我必须从此列表中删除重复项,但在这种情况下,"average"永远不会与原始原始列表匹配.

我所期待的3+6/2 = 4.5将永远是相同的3+3+6+6/4 = 4.5

.net c# ienumerable

0
推荐指数
1
解决办法
111
查看次数

Windows窗体应用程序C#中的后台工作程序不会阻止UI

我在我的win表单应用程序中使用后台工作程序我正在显示长时间运行进程的进度条形式,并且长时间运行的进程是在后台工作程序上.

注意:我使用后台工作程序来显示字幕样式的进度条.

我面临的问题是由于后台工作者我的用户界面得到响应,但我不希望它有响应.

我的代码如下:

ProgressBarForm progForm = new ProgressBarForm();
progForm.Show();
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork+= myMethod;
worker.RunWorkerAsync();
Run Code Online (Sandbox Code Playgroud)

c# winforms

-1
推荐指数
1
解决办法
933
查看次数

'DataClass.addrechargeplans(字符串,字符串,字符串,整数,字符串,字符串,字符串)'的最佳重载方法匹配有一些无效的参数

....的重载方法匹配有一些无效的参数在数据库中,我们有表名"RechargePlans",列名称是Circle,Operator,RechargeType,Amount,Talktime,Validity,Description

  protected void Button1_Click(object sender, EventArgs e)
  {
      int i = 0;
      i = obj.addrechargeplans(circleddl.SelectedItem.Text, operatorddl.SelectedItem.Value,rechargetype.SelectedItem.Text, amt, taktme.Text, valdty.Text, descpn.Text);
        if (i > 0)
        {
            Response.Write("<script>alert(' inserted')</script>");
        }
        else
        {
            Response.Write("<script>alert('error')</script>");
        }
     }
Run Code Online (Sandbox Code Playgroud)

数据类

public int addrechargeplans(string Circle, string Operator, string RechargeType, int     Amount, string Talktime, string Validity, string Description)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "sp_rechargeplans";
        cmd.Parameters.AddWithValue("@circle", Circle);
        cmd.Parameters.AddWithValue("@operator", Operator);
        cmd.Parameters.AddWithValue("@rechargetype", RechargeType);
        cmd.Parameters.AddWithValue("@amount", Amount);
        cmd.Parameters.AddWithValue("@talktime", Talktime);
        cmd.Parameters.AddWithValue("@validity", Validity);
        cmd.Parameters.AddWithValue("@description", Description); …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net visual-studio-2010

-2
推荐指数
1
解决办法
105
查看次数

我的程序没有代码运行

在我开始使用XNA游戏后,我的程序出现了一个非常奇怪的问题,我不知道我的程序从哪里得到它的代码,因为当我在visual studio 2008 c#中评论我的所有代码时,什么都不应该工作,但游戏仍然正常启动,没有任何问题.我不知道如何解决这个问题,我希望你们其中一个人知道为什么我的程序在我评论所有代码后仍然运行正常.如果我删除了我的所有代码程序仍然运行,我希望你们中的一个人可以告诉我Visual Studio 2008从哪里获取它的代码,或者解决这个问题.

当你无法理解我的问题时,请告诉我.

c# xna visual-studio-2008

-3
推荐指数
1
解决办法
110
查看次数

在MessageBox或WriteLine中创建字符串

我有一个问题,我现在并不是真的需要它,但我只是很好奇.

有没有办法创建一个字符串并将其填充在WriteLine或Messagebox.Show的括号之间?

那么代码应该看起来像我想的那样:

MessageBox.Show(String s = string.Format("Hello World"));
Run Code Online (Sandbox Code Playgroud)

这不是正确的代码,我唯一的问题是:这样的事情可能吗?

c# string messagebox

-3
推荐指数
1
解决办法
487
查看次数

在C#中将字符串拆分为两个子字符串

如何在c#中使用Split函数从字符串"tulip.jpg"中获取字符串"tulip"?

string str = "tulip.jpg";
Run Code Online (Sandbox Code Playgroud)

我将结果"tulip"存储在str1中(字符串类型为valiable).

c#

-4
推荐指数
1
解决办法
495
查看次数