我对数值分析很感兴趣.我一直在使用DotNumerics开源应用程序.我的线性系统如下:
1 * x + 3 * y <= 150
2 * x + 1 * y <= 100
Run Code Online (Sandbox Code Playgroud)
哪里 x >= 0, y >= 0
z = 10 * x + 15 * y
Run Code Online (Sandbox Code Playgroud)
我想解决z(优化......)
我可以使用Simplex方法来解决此链接中的上述问题.我也通过电子邮件发送了作者,但他没有回复.
using DotNumerics.Optimization;
using DotNumerics;
namespace App.SimplexCalcLinearProgramming
{
class Program
{
static void Main(string[] args)
{
Simplex simplex = new Simplex();
double[] initialGuess = new double[2];
initialGuess[0] = 0.1;
initialGuess[1] = 2;
double[] minimum = simplex.ComputeMin(AmacFunction, initialGuess);
minimum.ToList().ForEach(q => Console.Write(q.ToString() + …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,其中有UserControl一个工具栏.此工具栏有一个按钮Execute,该按钮又将其命令绑定到ICommand视图模型作为属性公开的派生类.
<Button Grid.Row="0" Command="{Binding ExecuteCommand}">Execute</Button>
Run Code Online (Sandbox Code Playgroud)
现在,我想将它绑定到键盘快捷键(F5).这需要在以后的上下文中绑定,UserControl仅当此用户控件此时可见时才适用.
另一种选择是将它绑定到KeyDown实际包含要执行的文本的文本框中,但是当涉及到如何将事件从控件路由到视图模型中的命令时,我真的很不稳定,而代码中没有真正难看的黑客攻击 - 用户控件的后面.
任何指针都表示赞赏!
好的我有这个项目我在WPF(Visual C#2010 Express)上工作,我有几个DatePickers绑定到DateTime属性.现在如果我打开"选择器"并立即开始更换几个月就没有问题了.但是,如果我选择日期然后尝试更改月份,则会出现以下异常:
元素不存在或虚拟化; 如果支持,请使用VirtualizedItem Pattern.
堆栈跟踪仅显示:
[外部代码]
我的方法打开包含DatePickers的对话框(除其他外)
[外部代码]
如果属性可以为空或者似乎没有区别,并且无法在上述异常的任何主要搜索引擎上找到单个结果.
XAML
<Window x:Class="WpfApplication1.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" Loaded="Window_Loaded">
<Grid>
<DatePicker SelectedDate="{Binding TheDate}"
x:Name="datePicker1" />
<Button Content="Button"
x:Name="button1"
Click="button1_Click" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
代码背后
class TheClass
{
public DateTime TheDate { get; set; }
}
public MainWindow()
{
theClass = new TheClass();
theClass.TheDate = DateTime.Now;
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.DataContext = theClass;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
System.Windows.MessageBox.Show(theClass.TheDate.ToString());
}
Run Code Online (Sandbox Code Playgroud)
有没有人见过这种行为或有任何其他想法?我离WPF专家很远,老实说不知道是什么导致这个或从哪里开始寻找..
你好,
我正在使用LINQ和EF与C#4.0.我已将基本的ELMAH表拖入EF(已构建并保存了很多次).一切都按照人们的预期运作.
但是试图过于雄心勃勃并需要一些帮助 - 我试图从作为变量传入的表达式中获取Column名称.
我想要的是这个:
传入:x => x.ErrorId
得到:"ErrorId"
public void GetColumnName(Expression<Func<T, object>> property)
{
// The parameter passed in x=>x.Message
// Message works fine (probably because its a simple string) using:
string columnName = (property.Body as MemberExpression).Member.Name;
// But if I attempt to use the Guid or the date field then it
// is passed in as x => Convert(x.TimeUtc)
// As a result the above code generates a NullReference exception
// i.e. {"Object reference not set to …Run Code Online (Sandbox Code Playgroud) 我正努力为我的一个课程进行单元测试.我想注入我的工厂,而不是autofac解决的自动生成的工厂.如何将自己的函数注册为代理来替换自动生成的委托工厂?
我的代码看起来像这是大纲形式:
interface IEntryImporter { ... }
class EntryImporter : IEntryImporter {
public EntryImporter(ISeries series, IMatch match, Entry.Factory entryFactory) {
:
}
:
}
interface IEntry : { ... }
class Entry : IEntry {
public delegate IEntry Factory();
public Entry() { ... }
}
interface IMatch : { ... }
class Match : IMatch { ... }
interface ISeries : { ... }
class Series : ISeries { ... }
void IEntry MyEntryFactory() {
var entry = new Mock<IEntry>(); …Run Code Online (Sandbox Code Playgroud) 查询字节属性的nhibernate 3.1.0.4000是否有任何问题:
byte code = 2;
Group g = Repository<Group>.FindOne(p => p.Code == code);
Run Code Online (Sandbox Code Playgroud)
例外文字:
Cause 'Specified cast is not valid.'
[InvalidCastException: Specified cast is not valid.]
NHibernate.Type.ByteType.Set(IDbCommand cmd, Object value, Int32 index) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Type\ByteType.cs:44
NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Type\NullableType.cs:180
...
[GenericADOException: could not execute query
[ select group0_.LabourLawGroupId as LabourLa1_235_, group0_.Code as Code235_ from personnel.LabourLawGroup group0_ where group0_.Code=? ]
Name:p1 - Value:4
[SQL: select group0_.LabourLawGroupId as LabourLa1_235_, group0_.Code as Code235_ from personnel.LabourLawGroup group0_ where group0_.Code=?]]
NHibernate.Loader.Loader.DoList(ISessionImplementor …Run Code Online (Sandbox Code Playgroud) 我有一个单维数组的项目声明和初始化为:
string[] SubDirectorylist = Directory.GetDirectories(TargetDirectory);
Run Code Online (Sandbox Code Playgroud)
我想扭转成员并找到Enumerable.Reverse<TSource>().
LINQ的反向实现有哪些优势(如果有的话)Array.Reverse()?
我正在制作一个简单的演示来学习如何创建一个可绑定的用户控件.我创建了一个简单的类:
class Person
{
public string firstName;
public string lastName;
public Person(string first, string last)
{
firstName = first;
lastName = last;
}
}
Run Code Online (Sandbox Code Playgroud)
而且一个非常简单的用户控件:
<UserControl x:Class="Example.ExampleHRControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock x:Name="textFirstName"></TextBlock>
<TextBlock x:Name="textLastName"></TextBlock>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我想知道的是,为了能够像普通控件一样在上下文中使用用户控件,我需要做什么.我可以添加到MainWindow:
<local:ExampleHRControl x:Name="Hr1"></local:ExampleHRControl>
Run Code Online (Sandbox Code Playgroud)
然后我可以通过后面的代码解决它并添加值:
Hr1.textFirstName.Text = "John";
Hr1.textLasttName.Text = "Doe";
Run Code Online (Sandbox Code Playgroud)
我希望能够创建类的实例,Person并简单地将主窗口上的控件绑定到Person类.
我有一个Windows应用程序,我想引入TPL功能.场景是我有一个类,Process其中包含一个MailMessage传递给它的集合的方法,以及当前的IMAP连接(使用AE.Net.Mail).
我想将尽可能多的线程分离到Execute另一个类中的方法,该方法接受单个MailMessage项目,然后MailMessage分配给DB,然后使用IMAP连接MailMessage从服务器中删除它.
我并不担心跟踪进程 - 我正在处理大量的电子邮件,并且不担心如果我在写入数据库或删除时遇到一些错误.我只需要应用程序尽可能快地通过大量的MailMessages.
我一直在玩,Task<MailMessage>.Factory.StartNew但我真的不知道我在做什么.我似乎无法开始......这是我尝试过的:
Task test = Task.Factory.StartNew(() =>
{
foreach (var mailMessage in _mms)
{
new ProcessMessage().Execute(mailMessage, imapConn);
}
});
Run Code Online (Sandbox Code Playgroud)
我很确定我不应该在lamda表达式中有一个循环,当我运行它时它似乎没有进入ProcessMessage.Execute.
c# ×7
.net ×4
linq ×3
wpf ×3
alignment ×1
arrays ×1
autofac ×1
clr ×1
datepicker ×1
moq ×1
mvvm ×1
nhibernate ×1
unit-testing ×1
xaml ×1