我有这样的设置:
abstract class Foo {}
class Bar : Foo {}
Run Code Online (Sandbox Code Playgroud)
和其他形式的方法:
void AddEntries(List<Foo>) {}
Run Code Online (Sandbox Code Playgroud)
我试图使用类型对象列表调用此方法 Bar
List<Bar> barList = new List<Bar>()
AddEntries(barList);
Run Code Online (Sandbox Code Playgroud)
但这给了我错误:
无法从List <Bar>转换为List <Foo>
反正这个问题呢?我需要使用抽象类来保持方法定义.
0uc#中的含义是什么?示例上下文:
uint n = _seconds;
while (n > 0u) {
// TODO
};
Run Code Online (Sandbox Code Playgroud) 我在extJS标记字段中发现了一个非常奇怪的错误.使用tagfild后,我无法看到字段的上下箭头,以便在tagfield中查看选定的组件.
我创建了一个小提琴手,请在chrome和firefox中打开小提琴手并查看其中的区别.
这是小提琴的链接.
图像中的小提琴红圈是我在firefox中要求的.

任何人都可以给我一些想法.
我正在使用 MVVM 并遇到以下问题。我的 TextBox.Text 与 UpdateSourceTrigger=LostFocus 绑定(这就是用户想要的)。我有一个带有 SaveCommand CommandBinding 的按钮 - 这有效。现在我有一个带有 Strg+S 的 KeyBinding,它也执行 SaveCommand。这就是问题所在:当我在文本框中并按 Strg+s 时,更改不在视图模型中。
有没有办法让 MVVM 命令与 KeyBinding 和 TextBox UpdateSourceTrigger=LostFocus 一起工作?
一些代码来检查问题
<Window>
<Window.InputBindings>
<KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand}"></KeyBinding>
</Window.InputBindings>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="{Binding MyText1, UpdateSourceTrigger=LostFocus}" Width="100"></TextBox>
<Button Grid.Row="1" Content="_Save" Command="{Binding SaveCommand}" IsDefault="True"></Button>
</Grid>
</Window>
public partial class MainWindow : Window
{
private Viewmodel _data;
public MainWindow()
{
_data = new Viewmodel();
InitializeComponent();
this.DataContext = _data;
}
}
public …Run Code Online (Sandbox Code Playgroud) 我想通过选择带有“以上全部”的复选框名称来选中所有复选框。复选框位于列表框中
<ListBox SelectionMode="Multiple"
BorderThickness="0"
ItemsSource="{Binding QuestionThreeSelection}"
SelectedItem="{Binding QuestionThreeSelection}"
Name="listBoxList"
SelectionChanged="listBoxList_SelectionChanged">
<ListBox.InputBindings>
<KeyBinding Command="ApplicationCommands.SelectAll"
Modifiers="Ctrl"
Key="A" />
</ListBox.InputBindings>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Checked="CheckBox_Checked_1"
Content="{Binding SourceName}"
IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
返回代码
private void CheckBox_Checked_1(object sender, RoutedEventArgs e)
{
var oo = listBoxList;
CheckBox cb = (CheckBox)sender;
//var w=e;
IEnumerable<AddSource> listallityem = ((IEnumerable<AddSource>)listBoxList.Items.SourceCollection).Where(r => r.IsSelected == false);
//IEnumerable<AddSource> listallityem1 = ((IEnumerable<AddSource>)listBoxList.Items.SourceCollection);
AddSource vv = cb.DataContext as AddSource;
if ((bool) cb.IsChecked)
{
}
if (vv.SourceName== "All of the above")
{
r …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
DateTime start = DateTime.Now;
Thread.Sleep(60000);
DateTime end = DateTime.Now;
Run Code Online (Sandbox Code Playgroud)
我想计算开始和结束之间的分钟差异.我该怎么办呢?对于上面的示例,结果应为"1".
提前致谢!
我有一个带有整数输入数组的控制器方法,它不能为null或大于10个元素.为了验证输入,我做了一个课程:
public class TestForm
{
[Required]
[MaxLength(10)]
public long[] feedIds { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和控制器方法:
[HttpPost]
public async Task<IActionResult> DoSomeJob(TestForm form)
{
//Do some job
}
Run Code Online (Sandbox Code Playgroud)
根据MSDN,System.ComponentModel.DataAnnotations.MaxLength可以用于数组,但是没有验证,它获取null和任何大小的数组.我究竟做错了什么?
我有抽象类,它是:
public abstract class Ingredient
{
private string name;
private decimal price;
public Ingredient(string name, decimal price)
{
this.name = name;
this.price = price;
}
public string Name
{
get
{
return this.name;
}
}
protected decimal Price
{
get
{
return this.price;
}
}
protected void ChangePrice(decimal newPrice)
{
Console.WriteLine(string.Format("The price changed from {0} to {1} for engridient {2}", this.price, newPrice,this.name));
this.price = newPrice;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有很多成分继承成分:
Tomato:Ingredient {//implementation}
Cheese:Ingredient {//implementation}
Mushrooms:Ingredient {//implementation}
Onion:Ingredient {//implementation}
Run Code Online (Sandbox Code Playgroud)
但我想我的成分,有一些类型的测量可以decimal Quantity或者 …
我想知道为什么我在命名空间范围之外定义它时可以访问类?
我对命名空间不太熟悉,我只是在学习,但我认为命名空间应该将我的所有类都包装到一个"盒子"中,并且它们可以在"盒子"(范围)内部相互访问.
代码示例:
class Point
{
public int X;
}
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
Point p = new Point();
p.X = 50;
Console.WriteLine(p.X);
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的回答.
long[] orderIds={10,11,12,13};
var orders= new List<Order>();
await Task.WhenAll(orderIds.Select(async (orderId) =>
{
var orderDetails = await GetOrderDetails(orderId);
if (orderDetails != null)
orders.Add(orderDetails);
}));
Run Code Online (Sandbox Code Playgroud)
我遇到了一些错误的行为,部署此代码以使其工作正常后,但在本地有时会添加所有订单,但有时会错过一些订单。
任何人都可以帮忙缩短这个,不知道我错过了什么。
c# ×8
.net ×3
wpf ×2
asp.net ×1
checkbox ×1
class ×1
css ×1
datetime ×1
extjs ×1
generics ×1
html ×1
inheritance ×1
javascript ×1
key-bindings ×1
mvvm ×1
namespaces ×1
time ×1
validation ×1