小编lep*_*pie的帖子

从对象列表生成字符串列表

我有一个对象列表。我对将每个对象的一个​​属性(一个字符串值)隔离到字符串列表中很感兴趣。如何仅使用此字段(最好使用Linq而不手动循环)创建字符串列表?

class MyObj
{
  int ID {get;set;}
  int AnotherID (get;set;}
  string IneedThis {get;set;}
}

List<MyObj> sampleList = somehow_this_is_populated();
List<string> ls = how do I get this list with values equal to "sampleList.IneedThis"
Run Code Online (Sandbox Code Playgroud)

.net c# linq

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

替换所有程序的Windows快捷方式

是否有可能让我的覆盖优先于系统范围,所以即使在运行Web浏览器,文字编辑器或绘图程序时(我的应用程序仍将在后台运行或显然是作为服务运行)

使用Visual C#2010

我如何覆盖我的代码的示例:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) 
{
    if((keyData == (Keys.Control | Keys.C))
    {
         //your implementation
         return true;
    } 
    else if((keyData == (Keys.Control | Keys.V))
    {
         //your implementation
         return true;
    } 
    else 
    {
        return base.ProcessCmdKey(ref msg, keyData);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# service hotkeys

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

"StyleCop"SA1300在GlobalSuppressions.cs类中没有抑制

我试图通过这行代码抑制SA1300的Style Cope警告.

[SuppressMessage("StyleCop.CSharp.NamingRules","SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Reviewed.")] 
Run Code Online (Sandbox Code Playgroud)

它在类级别工作(即如果我把它放在有警告然后工作的类中)但是如果我把它放在GlobalSuppressions.cs类中则不行.我想要抑制整个程序集的SA1300警告,所以我把这行放在GlobalSuppressions.cs中,但它没有用.

[assembly: SuppressMessage("StyleCop.CSharp.NamingRules","SA1300:ElementMustBeginWithUpperCaseLetter", MessageId = "Ctl", Scope = "namespace", Target = "Assembly name"))]
Run Code Online (Sandbox Code Playgroud)

是否可以在"GlobalSuppressions.cs"中执行此操作?它也不适用于"SA1600"

.net c# stylecop

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

DefaultIfEmpty 返回 null

我正在与C#, .NET4.5, EF6(实际上应该不重要)。

我从数据库中选择一些值,然后.ToList()添加它们,DefaultIfEmpty(new ActualFee{Net = 0, Vat = 0})如果不存在则添加,然后我得到null

public static ConveyancingSummaryVm ToConveyancingSummaryVm(this Tuple<IEnumerable<ActualFee>, ConveyancingAnswer, Customer> conveyancePricingAnswersAndCustomer)
        {
            var purchaseFees = conveyancePricingAnswersAndCustomer.Item1.Where(o => o.ConveyancingSaleType == "Purchase").ToList();

            if (purchaseFees.Any())
            {
                var discount = purchaseFees.DefaultIfEmpty(new ActualFee{Net = 0, Vat = 0}).SingleOrDefault(o => o.Title.Contains("Discount")); 

                conveyancingSummaryVm.IsPurchaseFreehold = conveyancePricingAnswersAndCustomer.Item2.PropertyBoughtIsFreehold;
...
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我一定在这里遗漏了一些明显的东西。

.net c# linq entity-framework

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

执行forloop时发生IndexOutOfRangeException

IEnumerable<char> query = "Not what you might expect";
string vowels = "aeiou";
for (int i = 0; i < vowels.Length; i++)
query = query.Where (c => c != vowels[i]);
foreach (char c in query) Console.Write (c);
Run Code Online (Sandbox Code Playgroud)

发生异常IndexOutOfRangeException。为什么会发生这个异常,一切看起来都很好。

提前致谢。

解决方案

for (int i = 0; i < vowels.Length; i++)
{
char vowel = vowels[i];
query = query.Where (c => c != vowel);
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,这些代码有什么区别。请分享详细信息。

.net c#

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

在 jsdom 中使用 getComputedStyle

我无法使用 jsdom 获得颜色的计算样式值:

require("jsdom").env({
    html: '<html><head><style> html { color: red; } </style></head><body></body></html>',
    done: function(errors, window) {

        console.log('color: "'+window.getComputedStyle(window.document.body).color+'"');
    }
});
Run Code Online (Sandbox Code Playgroud)

之前的测试返回 "" 而不是 "rgb(255, 0, 0)" 或 "red" ...
(注意这在浏览器中正常工作)

我错过了什么吗?

javascript jsdom getcomputedstyle

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

如何使DataGridView.Rows.DividerHeight工作?

我试图使用dataGridView创建一个简单的数独界面。问题是我无法DividerHeight上班。下面的代码能够更改垂直分隔线的宽度,但不能更改水平分隔线的宽度:

   public partial class Form1 : Form
{
    private DataTable sudokuTable; 

    public Form1()
    {
        InitializeComponent();
        sudokuTable = getTable();
        dataGridView1.DataSource = sudokuTable;

        for (int i = 0; i < 9; i++){                        
            dataGridView1.Columns[i].Width = 25;
        }

        dataGridView1.Columns[2].DividerWidth = 5; //Working
        dataGridView1.Columns[5].DividerWidth = 5; //Working
        dataGridView1.Rows[2].DividerHeight = 5; //Not working
        dataGridView1.Rows[5].DividerHeight = 5; //Not working

    }


    private static DataTable getTable()
    {
        DataTable newDataTable = new DataTable();


        for (int i = 0; i < 9; i++)
        {
            newDataTable.Columns.Add("c" + i+1, typeof(int));                       
        } …
Run Code Online (Sandbox Code Playgroud)

.net c# datagridview winforms

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

引导表的宽度大小和colspan

当我使用colspan时,表格宽度不起作用。我需要科尔斯潘。宽度尺寸为100px;或没有colspan底部源代码宽度大小的10%的作品。我该如何编辑?我可以问吗?请帮忙。

<link href="css/bootstrap.min.css" rel="stylesheet">
<style>
  table {
table-layout: fixed;
word-wrap: break-word;
width: 30%;
 }
</style>
</head>
<body>
<table>
  <tr>
      <td colspan="2">abc</td>
 </tr>
  <tr class="table table-bordered">
      <td style="width: 10%;" /td>1</td>
      <td style="width: 20%;" /td>2</td>
  </tr>
</table>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script     src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
 </body>
</html>
Run Code Online (Sandbox Code Playgroud)

twitter-bootstrap

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

为什么sizeof(Point)是8?

我编写代码并得到奇怪的结果 - 整数我是8:

unsafe
        {
            int i = sizeof(Point);
        }
Run Code Online (Sandbox Code Playgroud)

检查struct Point后,我找到了这个字段:

    public bool IsEmpty { get; }
    public int X { get; set; }
    public int Y { get; set; }
Run Code Online (Sandbox Code Playgroud)

位数学:32 + 32 + 1 = 65位,因此> 8字节

那么,为什么sizeof返回8,而不是9?

谢谢

.net c# sizeof

3
推荐指数
2
解决办法
223
查看次数

可以在xml中使用<0> </ 0>吗?

我正在尝试构建一个XML文件(稍后将转换为JSON).

因此,我必须尊重模式,我需要将<0>和<1>放在XML中,但它不起作用.我也尝试将<\ 0>和<\ 1>放在一起,但它说它不是XML的好词.

<Result>
    <Content>
        <0></0>
        <1></1>
    </Content>
</Result>
Run Code Online (Sandbox Code Playgroud)

在Visual Studio的调试器中,我在目标中设置了一个断点来查看xml,但是使用<0>我不能将文档作为XML打开,只能作为Text.

我该如何解决这个问题?

xml string

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