小编The*_*iot的帖子

从x到y的共变阵列转换可能会导致运行时异常

我有一个s()private readonly列表.我稍后在此列表中添加s并将这些标签添加到以下内容中:LinkLabelIList<LinkLabel>LinkLabelFlowLayoutPanel

foreach(var s in strings)
{
    _list.Add(new LinkLabel{Text=s});
}

flPanel.Controls.AddRange(_list.ToArray());
Run Code Online (Sandbox Code Playgroud)

Resharper给我一个警告:Co-variant array conversion from LinkLabel[] to Control[] can cause run-time exception on write operation.

请帮我弄明白:

  1. 这意味着什么?
  2. 这是一个用户控件,多个对象不会访问它来设置标签,因此保持代码不会影响它.

c# .net-4.0 covariance winforms

135
推荐指数
5
解决办法
3万
查看次数

"折叠"LINQ扩展方法在哪里?

我在MSDN的Linq示例中找到了一个名为Fold()的简洁方法,我想使用它.他们的例子:

double[] doubles = { 1.7, 2.3, 1.9, 4.1, 2.9 }; 
double product = 
     doubles.Fold((runningProduct, nextFactor) => runningProduct * nextFactor); 
Run Code Online (Sandbox Code Playgroud)

不幸的是,无论是在他们的示例中还是在我自己的代码中,我都无法进行编译,而且我在MSDN中找不到任何其他地方(如Enumerable或Array扩展方法).我得到的错误是一个普通的"不知道任何关于那个"的错误:

error CS1061: 'System.Array' does not contain a definition for 'Fold' and no 
extension method 'Fold' accepting a first argument of type 'System.Array' could 
be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)

我正在使用其他我认为来自Linq的方法(比如Select()和Where()),我正在"使用System.Linq",所以我认为一切都好.

这种方法确实存在于C#3.5中,如果是这样,我做错了什么?

c# linq reduce extension-methods

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

Elmah没有使用asp.net网站

我试图在我的asp.net网站上使用elmah,但每当我尝试访问http:// localhost:port/elmah.axd时,我都会找到资源未找到异常.我的web.config如下所示.

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <sectionGroup name="elmah">
          <section name="security" requirePermission="false" 
                  type="Elmah.SecuritySectionHandler, Elmah"/>
          <section name="errorLog" requirePermission="false" 
                  type="Elmah.ErrorLogSectionHandler, Elmah" />
          <section name="errorMail" requirePermission="false" 
                  type="Elmah.ErrorMailSectionHandler, Elmah" />
          <section name="errorFilter" requirePermission="false" 
                  type="Elmah.ErrorFilterSectionHandler, Elmah"/>
        </sectionGroup>
      </configSections>
      <elmah>
        <security allowRemoteAccess="0" />
        <errorLog type="Elmah.SqlErrorLog, Elmah" 
                 connectionStringName="elmah-sql" />
        <errorMail
                from="my@account"
                to="myself"
                subject="ERROR From Elmah:"
                async="true"
                smtpPort="587"
                smtpServer="smtp.gmail.com"
                userName="my@account"
                password="mypassword" />
      </elmah>

      <connectionStrings>
        <add name="elmah-sql" connectionString="data source=(sqlserver); 
               database=elmahdb;
             integrated security=false;User ID=user;Password=password"/>
      </connectionStrings>
      <system.web>
        <compilation debug="true">
          <assemblies>
            <add assembly="Elmah, Version=1.0.10617.0, Culture=neutral, 
               PublicKeyToken=null"/>
          </assemblies>
        </compilation>
        <authentication mode="Windows"/>

        <httpHandlers> …
Run Code Online (Sandbox Code Playgroud)

asp.net elmah exception-handling

80
推荐指数
6
解决办法
3万
查看次数

如何正确停止BackgroundWorker


我有一个有2个组合框的表格.我想combobox2.DataSource基于combobox1.Text和填充combobox2.Text(我假设用户已完成输入combobox1并且正在输入中combobox2).所以我有一个这样的事件处理程序combobox2:

private void combobox2_TextChanged(object sender, EventArgs e)
{
    if (cmbDataSourceExtractor.IsBusy)
       cmbDataSourceExtractor.CancelAsync();

    var filledComboboxValues = new FilledComboboxValues{ V1 = combobox1.Text,
       V2 = combobox2.Text};
    cmbDataSourceExtractor.RunWorkerAsync(filledComboboxValues );
}
Run Code Online (Sandbox Code Playgroud)

至于构建DataSource是一个耗时的过程(它创建一个对数据库的请求并执行它)我决定使用BackgroundWorker在另一个进程中执行它更好.因此,当cmbDataSourceExtractor尚未完成其工作并且用户再键入一个符号时,会出现这种情况.在这种情况下,我在这一行上得到一个例外,
cmbDataSourceExtractor.RunWorkerAsync(filledComboboxValues );说明BackgroundWorker正忙,无法同时执行多个操作.
如何摆脱这种异常?
提前致谢!

.net c# backgroundworker winforms

60
推荐指数
3
解决办法
18万
查看次数

什么是SQL Server中的覆盖索引和涵盖查询?

你能解释微软SQL Server中覆盖索引和涵盖查询的概念和关系吗?

sql sql-server indexing

50
推荐指数
5
解决办法
10万
查看次数

System.IdentityModel.Tokens和Microsoft.IdentityModel.Tokens之间的冲突

使用System.IdentityModel.Tokens时出现冲突:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Text;

public voidGenereToken()
{
    const string sec = "401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1";
    var now = DateTime.UtcNow;
    var securityKey = new InMemorySymmetricSecurityKey(Encoding.Default.GetBytes(sec));
    var signingCredentials = new SigningCredentials(securityKey,
            SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest);

    var header = new JwtHeader(signingCredentials);

    var payload = new JwtPayload
    {
        {"iss", "a5fgde64-e84d-485a-be51-56e293d09a69"},
        {"scope", "https://example.com/ws"},
        {"aud", "https://example.com/oauth2/v1"},
        {"iat", now},
    };

    var secToken = new JwtSecurityToken(header, payload);

    var handler = new JwtSecurityTokenHandler();
    var tokenString = handler.WriteToken(secToken);
    Console.writeLine(tokenString)
}
Run Code Online (Sandbox Code Playgroud)

我创建标题时出现以下错误(var header = …

c# token jwt

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

C#中面向方面编程

是否有任何好的资源可以围绕面向方面编程?

PS:我需要了解AO编程,而不是.NET或C#可用的库或框架:)

.net c# aop

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

adodb和oledb有什么区别?

adodb和之间有什么区别oledb

这两者之间有什么关系?

哪里ado.net在上下文看台adodboledb

oledb ado.net adodb

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

将像素添加到jquery .css()左侧属性

这是我的代码:

var lef=$(this).css("left");
var top=$(this).css("top");
alert(lef);
$(this).after("<div class='edit cancel' style='position:absolute;top:"+top+";left:"+lef+"'>Cancel</div>");
Run Code Online (Sandbox Code Playgroud)

现在声明var lef=$(this).css("left") + 150,似乎没有用.我想得到左边的属性并添加150像素

我怎样才能做到这一点 ?

谢谢.

css jquery

33
推荐指数
2
解决办法
8万
查看次数

用json数据填充jquery填充下拉列表

我有以下jQuery代码.我能从服务器获取以下数据[{"value":"1","label":"xyz"}, {"value":"2","label":"abc"}].如何迭代并填充选择框id=combobox

$.ajax({
    type: 'POST',
    url: "<s:url value="/ajaxMethod.action"/>",
    data:$("#locid").serialize(),
    success: function(data) {
        alert(data.msg);

                //NEED TO ITERATE data.msg AND FILL A DROP DOWN
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert(textStatus);
    },
    dataType: "json"
});
Run Code Online (Sandbox Code Playgroud)

还有什么区别使用.ajax$.getJSON.

jquery json

29
推荐指数
3
解决办法
11万
查看次数