我有一个包含客户详细信息的课程。
class CustomerData : INotifyPropertyChanged
{
private string _Name;
public string Name
{
get
{ return _Name }
set
{
_Name = value;
OnPropertyChanged("Name");
}
}
// Lots of other properties configured.
}
Run Code Online (Sandbox Code Playgroud)
我还有一个CustomerData值列表List<CustomerData> MyData;
我目前databinding个人CustomerData反对textboxes以下工作正常的方式。
this.NameTxtBox.DataBindings.Add("Text", MyCustomer, "Name", false, DataSourceUpdateMode.OnPropertyChanged);
Run Code Online (Sandbox Code Playgroud)
我正在努力寻找一种将列表中的每个对象绑定MyData到ListBox.
我希望将 MyData 列表中的每个对象显示在显示名称的 ListBox 中。
我尝试将其设置DataSource为等于MyData列表并将其设置DisplayMember为“名称”,但是当我将项目添加到MyData列表中时,它listbox不会更新。
关于如何做到这一点有什么想法吗?
我有一个 453MB XML 文件,我正在尝试使用SharpZipLib将其压缩为 ZIP 。
下面是我用来创建 zip 的代码,但它导致了OutOfMemoryException. 此代码成功压缩了 428MB 的文件。
知道为什么会发生异常,因为我不明白为什么,因为我的系统有足够的可用内存。
public void CompressFiles(List<string> pathnames, string zipPathname)
{
try
{
using (FileStream stream = new FileStream(zipPathname, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (ZipOutputStream stream2 = new ZipOutputStream(stream))
{
foreach (string str in pathnames)
{
FileStream stream3 = new FileStream(str, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[stream3.Length];
try
{
if (stream3.Read(buffer, 0, buffer.Length) != buffer.Length)
{
throw new Exception(string.Format("Error reading '{0}'.", str));
}
}
finally
{ …Run Code Online (Sandbox Code Playgroud) 我试图在我的项目中使用第三方.net 4.6 dll.这个dll的大小是40mb,一切正常.
然而,加载我的DLL的应用程序中有一个错误,当加载的dll大于10mb时崩溃.这是固定的,但暂时还没准备好.
为了不拖延我的项目是否可以将.NET程序集拆分为更小的块,但仍然有引用程序集正确加载所有内容?
我在 Azure Devops 中创建了一个新的 YAML 管道。它几乎是另一个工作正常的管道的相同副本。
构建阶段工作正常,但是当它到达 terraform 脚本尝试执行时,我收到以下错误:
##[warning]There was a failure in sending the provision message: Unexpected response code from remote provider InternalServerError
,##[warning]There was a failure in sending the provision message: Unexpected response code from remote provider InternalServerError
,##[warning]There was a failure in sending the provision message: Unexpected response code from remote provider InternalServerError
,##[warning]There was a failure in sending the provision message: Unexpected response code from remote provider InternalServerError
,##[warning]There was a failure in sending the …Run Code Online (Sandbox Code Playgroud) 我试图让我的头脑绕多线程.
对于简单的任务,我发现最简单的方法是这样做:
new Thread(delegate()
{
Console.Writeline("doing stuff here");
}).Start();
new Thread(delegate()
{
Console.Writeline("doing other stuff here");
}).Start();
Run Code Online (Sandbox Code Playgroud)
我想知道的是,如果我在我的两个线程中调用一个方法,这会导致冲突:
new Thread(delegate()
{
dostuff();
}).Start();
new Thread(delegate()
{
dostuff();
}).Start();
private void dostuff()
{
Console.WriteLine("Do Stuff Here");
}
Run Code Online (Sandbox Code Playgroud) 以下示例简化了我的问题.在新线程中抛出异常.如果我不在线程中处理它,它不会被外部try/catch捕获并崩溃我的应用程序.
有没有办法保证我发现任何异常.
try
{
new Thread(delegate()
{
throw new Exception("Bleh"); // <--- This is not caught
}).Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Run Code Online (Sandbox Code Playgroud) 我有一个简单的 UserControl,我想将 Label 文本值绑定到 DLL 中的属性。我的主应用程序允许我通过指定 XAML 插入我自己的用户控件。
在下面的 XAML 中,我使用的 CheckSubtotal 属性是加载用户控件的应用程序的一部分。该属性填充到控件中不会出现任何问题。在下面的 XAML 中,TestValue 属性位于 MyTestDLL.dll 中,我已在 XAML 的开头指定了该属性。此属性未填充到控件中。
示例 DLL - MyTestDLL.dll
namespace MyTestNamespace
{
public class Application
{
public static string TestValue = "TestVal";
public Application()
{}
}
}
Run Code Online (Sandbox Code Playgroud)
XAML 示例
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:systemWindows="clr-namespace:System.Windows;assembly=PresentationFramework"
xmlns:local="clr-namespace:MyTestNamespace;assembly=MyTestDLL"
>
<Grid>
<DockPanel>
<Border DockPanel.Dock="Left" Width="294" Margin="3,0,4,3" CornerRadius="0,0,3,3" Padding="2" BorderBrush="Black" BorderThickness="0" Background="White">
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Stretch" Margin="5,0,5,0">
<Grid>
<Label FontSize="20" Content="SubTotal:" HorizontalAlignment="Left" Margin="10,0,0,0" Width="129.51"/>
<Label FontSize="20" HorizontalAlignment="Right" Margin="0,0,21,0" Content="{Binding Path=CheckSubtotal}"/> …Run Code Online (Sandbox Code Playgroud) 好让我们假设我有一个控制我的数据层的类和一个执行工作的类.
class MyData
{
public DataTable GetMyData()
{
return Query.MyDataBase.ResultDT();
}
}
class MyWork
{
public int DoWork()
{
MyData Data = new MyData();
DataTable DT = Data.GetMyData();
return DT.Rows.Count;
}
}
Run Code Online (Sandbox Code Playgroud)
如何在不访问数据库的情况下使用单元测试来测试我的DoWork方法.
[TestMethod()]
public void TestMyWork()
{
MyWork work = new MyWork();
int result = work.DoWork();
Assert.AreEqual(1, result);
}
Run Code Online (Sandbox Code Playgroud) 今天这个问题突然出现在我脑海中.
C#6.0或任何其他版本都引入了很酷的新功能,使代码更容易编写.
但是,假设我有一个运行WindowsXP的客户端,它不支持.NET 4.6.
在C#6.0中编写我的代码(或者将来最新的C#版本)是否有任何缺点,但是要针对.NET 2.0框架(或者与C#版本不同的.NET的某些其他版本)进行编译被释放了)
编辑
对于那些不知道的人,您可以通过项目属性 - >应用程序选项卡 - >目标框架来定位.NET Framework
您可以通过项目属性 - >构建选项卡 - >高级 - >语言版本来定位C#语言版本.
EDIT2 - C#6.0代码在.NET 2.0上编译并在WindowsXP上运行
static void Main(string[] args)
{
try
{
StringBuilder sb = null;
string value = sb?.ToString(); // C#6 Feature. Wont throw an exception.
if(value == null)
{
Console.WriteLine("The Value is null");
}
string value2 = sb.ToString(); // Will cause an "Object Reference not set to an instance" exception
}
catch ( Exception ex) when (ex.Message.Contains("object")) // C#6.0 …Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×2
azure ×1
azure-devops ×1
c#-6.0 ×1
compression ×1
data-binding ×1
database ×1
frameworks ×1
ilmerge ×1
listbox ×1
namespaces ×1
sharpziplib ×1
split ×1
terraform ×1
unit-testing ×1
winforms ×1
wpf ×1
xaml ×1
yaml ×1