小编Sal*_*ari的帖子

从哈希表中查找值

如果我有一个通用列表,我会做这样的事情

myListOfObject.FindAll(x=>(x.IsRequired==false));
Run Code Online (Sandbox Code Playgroud)

如果我需要做类似的事情Hashtable怎么办?复制到临时hashtable和循环和比较将是我会尝试的最后一件事:-(

.net c# collections hashtable

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

如何从其子控件访问 ListViewItem?

我有一些ListViewItem来自集合的 s,我创建了一个DataTemplate ,以便每个ListViewItem都有 aButton作为子控件:

<Window.Resources>
    <DataTemplate x:Key="ItemTemplate_AwesomeTemplate">
        <StackPanel Orientation="Vertical" VerticalAlignment="Stretch">
            <Button Content="Awesome Button" Click="Awesome_Button_Click" HorizontalContentAlignment="Center" VerticalAlignment="Bottom" FontWeight="Bold" Foreground="Black"/>
        </StackPanel>
    </DataTemplate>
</Window.Resources>

<ListView x:Name="AwesomeListView" HorizontalAlignment="Left"  Height="577" VerticalAlignment="Top" Width="934" ScrollViewer.HorizontalScrollBarVisibility="Visible" Foreground="Black" Margin="10,10,0,0">
  <ListView.View>
    <GridView>
       <GridViewColumn Header="AwesomeHeader" Width="250" CellTemplate="{StaticResource ItemTemplate_AwesomeTemplate}"/>
    </GridView>
  </ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)

当我单击某个时Button,有没有办法更改包含单击IsSelected的属性?ListViewItemButton

c# wpf listviewitem

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

无法找到我的EF代码第一个数据库

我正在做Microsoft的MVC入门教程:

实体框架6入门代码首先使用MVC 5.

这包括创建代码优先数据库.

一切正常,但我无法找到我的数据库.

这是我的ConnectionString:

<add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True" providerName="System.Data.SqlClient"/>
Run Code Online (Sandbox Code Playgroud)

如果我调试我的索引方法连接如下:

Data Source=.\SQLEXPRESS; Integrated Security=True
Run Code Online (Sandbox Code Playgroud)

但是我的SQLEXPRESS实例中没有数据库,我已经使用SQL Server Management Studio进行了检查.

如果我搜索我的文件系统,我也找不到任何东西*.mdf.

App_Data 在我的项目是空的...

但是所有的CRUD操作都运行良好,必须有一些东西.

我能看到该表的唯一方法是.\SQLEXPRESS通过Visual Studio Server Explorer连接.但这个位置在哪里?如果我.\SQLEXPRESS通过SQL Server Management Studio 连接,为什么我看不到该表?

任何的想法?

c# sql-server asp.net-mvc entity-framework

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

如何检查 WMI 查询是否返回 0 行?

我正在编写一个明显错误的 C# 代码。我正在尝试使用 WMI 查询获取随身碟数据,并在继续操作后,检查查询是否返回 0 行以避免错误。

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_USBDevice");
ManagementObjectCollection drive = searcher.Get();
if (drive == null)
{
    MessageBox.Show("Failed to read data.");
    Application.Exit();
}
Run Code Online (Sandbox Code Playgroud)

显然这个drive == null方法是行不通的。我怎样才能以正确的方式检查它?而且,这是获取随身碟数据的正确方法吗?

c# wmi

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

随机数字列表

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{
   int i;
   int diceRoll;

   for(i=0; i < 20; i++)
   {
       printf("%d \n", rand());
   }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是我在c(codeblocks)中编写的代码来获取随机数,问题是我总是得到相同的序列:41,18467,6334,26500等等...

我还在学习,所以请尝试解释,就像你正在和一个8岁的D谈话:

c c++ random codeblocks

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

继承和基础构造函数

所以我正在努力教自己编程,我正在为练习制作一场RPG战斗.(基本上只是c#中一个非常简单的旧RPG战斗系统)但是,我对继承有点困惑.所以我有一个基类敌人:

class Enemy
{
    public string name;
    public int health;
    public int attack;
    public int level;

    public Enemy(string _name, int _health, int _attack, int _level)
    {
        name = _name;
        health = _health;
        attack = _attack;
        level = _level;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我有这个课Dragon:

class Dragon : Enemy
{

}
Run Code Online (Sandbox Code Playgroud)

为什么这么说呢

没有给出的参数对应于'Enemy.Enemy(string,int,int,int)所需的形式参数'_name'?

我的想法是它会使用敌人的构造函数,我是否必须使每个派生类成为自己的构造函数?

c# oop inheritance

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

不能在此范围内声明名为“e”的本地或参数

我正在尝试使用此代码:

var controls = new[] { txtName, txtIdentityCard, txtMobile1 };
foreach (var control in controls.Where(e => String.IsNullOrEmpty(e.Text))) // error here in (e)
{
    errorProvider1.SetError(control, "Please fill the required field");
}
Run Code Online (Sandbox Code Playgroud)

检查我的文本框之一是否为空,但出现以下错误:

无法在此范围内声明名为“e”的本地或参数,因为该名称用于封闭本地范围以定义本地或参数

有什么帮助吗?

.net c# linq

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

docker swarm抛出错误“ swarm已经是swarm的一部分”

当我将新节点加入现有节点时,docker swarm抛出错误“ swarm已经是swarm的一部分”

我在本地计算机上运行docker swarm并尝试初始化swarm并获得很好的执行,但是当我尝试将新的worker或节点添加到现有的manager节点时,它会抛出错误,例如swarm已经是节点,您必须离开该节点。$ docker swarm init Swarm已初始化:当前节点(fn405d6jtk8mxbpvdrftr0np1)现在是管理员。

要将工作程序添加到该群集,请运行以下命令:

docker swarm join --token SWMTKN-1-5tyw8ux789wpa7yyt75qbilb669tiw53pxriyxu48niznpmaka-7u63l4hom3h60myvtyw8p1mcj 192.168.2.219:2377
Run Code Online (Sandbox Code Playgroud)

要将管理器添加到该群,请运行“ docker swarm join-token manager”并按照说明进行操作。

=>然后再次使用上述令牌作为工作人员并加入,然后我会收到这样的错误。

$    docker swarm join --token SWMTKN-1-5tyw8ux789wpa7yyt75qbilb669tiw53pxriyxu48niznpmaka-7u63l4hom3h60myvtyw8p1mcj 192.168.2.219:2377

Error response from daemon: This node is already part of a swarm. Use "docker swarm leave" to leave this swarm and join another one.
Run Code Online (Sandbox Code Playgroud)

python docker docker-swarm

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

如何覆盖默认的必需错误消息

我有一个旧的 C# MVC 2.0 Web 应用程序。

每当我使用[Required]属性时,默认的验证错误消息都会显示:

[whatever] 字段是必需的。

我的问题是应用程序不是英文的,所以我基本上必须将属性调用更改为[Required(ErrorMessage = "Le champ [whatever] est requis.")]无处不在。

有没有办法覆盖默认错误消息,以便我只需要在需要特定消息时指定它?

我正在寻找类似的东西:

DefaultRequiredMessage = "Le champ {0} est requis.";
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc data-annotations asp.net-mvc-2

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

复杂类型需要主键

我有一个对象,其中包含一个具有另一个对象类型的属性,我想将其视为复杂类型。

public class Location : IModule
{
    public string Id { get; set; }
    public Coordinate Coordinate { get; set; }
}

[ComplexType]
public class Coordinate
{
    public string Latitude { get; set; }
    public string Longitude { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在添加迁移时,我遇到了需要主键的问题(正是我想要防止的)。

实体类型Coordinate需要定义一个主键。

编辑

出于性能原因,我希望将属性存储为Coordinate_LatitudeCoordinate_Longitute不是引用另一个表。

.net c# entity-framework primary-key

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