小编Met*_*urf的帖子

List <string []>显示列表值

我有生成List<string[]>变量的代码,但无法弄清楚如何使其正确显示在文本框中.

List<string[]> test = parseCSV();
for (int i = 0;  i < test.Count; i++)
{
  Console.WriteLine("i = {0}",i);
  Console.WriteLine("test[i] = {0}", test[i]);
  nameList.Text = test[i].ToString() + "\n" + nameList.Text;
}
Run Code Online (Sandbox Code Playgroud)

当我输出test[i]到控制台时,它正确显示字符串信息,但当我输出test[i]到文本框时,我得到:

System.String[]
System.String[]
System.String[]
System.String[]
System.String[]
System.String[]
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我做错了什么?

c# winforms

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

如何将字符串分成多个部分C#

我有一个包含链接的字符串.例:

www.google.com;www.yahoo.com;www.gmail.com
Run Code Online (Sandbox Code Playgroud)

我的问题是我如何分离这些链接,以便我可以添加标签的所有链接<a>以及链接末尾的标记</a>

我应该得到这个:

<a>www.google.com</a>;<a>www.yahoo.com</a>;<a>www.gmail.com</a>
Run Code Online (Sandbox Code Playgroud)

如果解决方案尽可能简单并使用该IndexOf方法,我将感激不尽.

c# string

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

WPF,如果基于单选按钮的语句已选中

我在某些似乎很简单的事情上遇到了困难。我来自Windows窗体,并从WPF开始。我认为我有一个简单的语法问题,但似乎无法找到此单选按钮问题的具体示例。

我的GUI上有一个单选按钮,可通过地图选择或列表来运行查询。单击加载时,如果选择了地图,它将执行一项操作,对列表执行另一项操作。代码类似于以下内容:

private void Load_Click(object sender, RoutedEventArgs e)
{
  if (rdBtnList.Checked == true)
  {
    //do this
  }

  // if rdBtnList not checked (ie if rdBtnMap is checked)
  // do this
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。谢谢。

wpf checked jradiobutton

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

在嵌套for循环中苦苦挣扎

给定主数字和数字子集,想要找到加起来主数字的子集数的所有可能组合.例如:

INPUT

主要:10
子集:2,3,5,7

OUTPUT

结果:3 + 7 = 10,2 + 3 + 5 = 10
**注意:5 + 5 = 10不是有效结果.**

这是我到目前为止的地方:

// Main traversal
for (int a = 0; a < nums.Length; a++)
{
    sum = a;

    for (int b = a + 1; b < nums.Length; b++)
    {
      // Thinking this should be the loop that determines 
      // how many numbers are added together. 
      // e.g. Sum of 2 numbers, sum of 3 numbers, etc
        for (int c …
Run Code Online (Sandbox Code Playgroud)

c# loops for-loop

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

ThreadPool参数

在我将它放入我的应用程序之前,我正在测试一个简单的线程池解决方案,但我看到的结果对我来说没有意义.我有一个简单的表单,上面有一个按钮.此按钮启动以下循环:

private void button1_Click(object sender, EventArgs e)
{
    MyTestThread oTask = new MyTestThread ();
    MyThreadInfo oTaskParameters = new MyThreadInfo();
    for (int i = 1; i <= 5; i++)
    {
        objTaskParameters.MyGuid = Guid.NewGuid();
        objTaskParameters.MyNumber = i;
        ThreadPool.QueueUserWorkItem(new WaitCallback(objTask.ProcessDataForNTime), objTaskParameters);
    }
    Console.WriteLine("All threads have been queued for processing...");
}
Run Code Online (Sandbox Code Playgroud)

它正在调用的类看起来像这样.它有一个参数MyThreadInfo类,然后MyTestThread类在完成之前循环10秒.

public class MyThreadInfo
{
    public int MyNumber;
}

public class MyTestThread 
{
    public void ProcessDataForNTime(Object oParameters)
    {
        //We pass parameters
        MyThreadInfo oThread = (MyThreadInfo)oParameters;
        int threadNo = oThread.MyNumber;

        Console.WriteLine("thread {0} started...", threadNo); …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading threadpool

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

WPF无法从变量更新文本框

使用WPF和VB.net,我想用当前日期和时间更新文本块中的文本框.我使用计时器,它似乎正在触发,并将对象属性设置为"现在".我正在使用iNotifyPropertyChanged.

我得到的只是一个没有数据的空文本框.你能帮我吗?也许我的背景是关闭的?

XAML

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
    <TextBlock DataContext="oTime"> 
        <TextBox x:Name="myTextBox" 
                 Width="200" Height="50" Foreground="Black" 
                 Text="{Binding Path=oTime.TimeUpdate}"></TextBox>
    </TextBlock>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

VB代码

Imports System.ComponentModel
Imports System.Windows.Threading

Class MainWindow
  Public oTime As TimeUpdate = New TimeUpdate
  Private dpTimer As DispatcherTimer

  Private Sub TextBlock_SourceUpdated(ByVal sender As System.Object, ByVal e As System.Windows.Data.DataTransferEventArgs)

  End Sub

  Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
      dpTimer = New DispatcherTimer
      dpTimer.Interval = TimeSpan.FromMilliseconds(1000)
      AddHandler dpTimer.Tick, AddressOf TickMe
      dpTimer.Start()
  End Sub

  Private …
Run Code Online (Sandbox Code Playgroud)

vb.net wpf binding inotifypropertychanged

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

等待下载完成时取消 WebClient 下载

寻找一种更普遍接受的等待模式WebClient

  • 下载文件(可能需要几百毫秒或几分钟)
  • 等待下载完成后再执行任何其他工作
  • 定期检查另一个类的标志 (bool) 并根据需要取消下载(无法修改此类)

限制条件:

  • 不能使用 async/await 除非它是类似的Task.Run(async () => await method())
  • Download调用该方法时,它只需要像普通方法一样返回字符串
  • 可以使用 .Net 4.5 和 Roslyn 编译器的任何功能
  • 是否使用WebClient.DownloadFileTaskAsync或 都没有区别;DownloadFileAsync只需能够根据需要使用取消下载WebClient

当前的实现似乎有效,但似乎不太正确。是否有比使用while循环并在使用时Thread.Sleep定期检查更普遍可接受的替代方案?otherObject.ShouldCancelWebClient

private string Download(string url)
{
    // setup work
    string fileName = GenerateFileName();

    // download file
    using (var wc = new WebClient()) 
    {
        wc.DownloadFileCompleted += OnDownloadCompleted

        Task task = wc.DownloadFileTaskAsync(url, fileName);

        // Need to wait until either the download is completed …
Run Code Online (Sandbox Code Playgroud)

c# webclient cancellation

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