小编Chr*_*tos的帖子

为什么我不能声明具有已经声明的相同名称的变量,但是新变量超出了其他变量的范围

private void Abc()
{
    string first="";
    ArrayList result = new ArrayList();
    ArrayList secResult = new ArrayList();
    foreach (string second in result)
    {
        if (first != null)
        {
            foreach (string third in secResult)
            {
                string target;
            }
        }

        string target;//Here I cannot decalre it. And if I don't declare it and
        //want to use it then also I cannot use it. And if it is in if condition like
        //the code commented below, then there is no any complier error.
        //if …
Run Code Online (Sandbox Code Playgroud)

c# foreach scope

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

C#如何纠正数组中的错误输入

所以我需要和学生一起上课.输入必须在0-100之间,否则它不接受来自用户的输入.

  Console.WriteLine("How many students?");
  int num1 = Keyboard.ReadInt();
  int[] array = new int[num1];
  Console.WriteLine("Give the student grades: ");
  for (int i = 0; i < array.Length; i++)
  {
      int wrong;
      wrong = Keyboard.ReadInt();
      if (wrong > 0 && wrong <= 100)
      {
          array[i] = wrong;
      }
      else
      {
          while (wrong < 0 && wrong >= 100)
          {
              Console.WriteLine("Wrong input:");
              wrong = Keyboard.ReadInt();
          }
      }
Run Code Online (Sandbox Code Playgroud)

c# arrays loops input

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

C编程中的简单链接列表结构

这是我在C中的第一个链接列表程序,我试图初始化节点的值并尝试打印它.但是,它没有给我预期的输出.谁能让我知道我哪里错了?

#include<stdio.h>
#include<stdlib.h>
struct node
{
    int key;
    struct node *next;
};

typedef struct node NODE;

int main ()
{
    NODE a,b,c;
    NODE *list;
    list=&a;
    list->key = 10;
    list->next = &b;
    list->next->key=20;
    list->next->next=&c;
    list->next->next->key=30;
    list->next->next->next=NULL;
    printf("%d  %d  %d", a,b,c);
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

它打印10和20之间有一些垃圾.

c linked-list

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

EPPlus多个标签c#

我正在使用EPPlus导出excel.我已经完成了一些功能来获得"ExcelWorksheet".我想在一个excel(每个标签一个)中使用它加入所有这些,但我不知道我该怎么做.

这是主要功能:

public ActionResult ExportReports(string sheetName)
{
    try
    {
        var req = GetRequest();
        var fileDownloadName = "OnlineReport.xlsx";
        var contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

        var package = new ExcelPackage();
        var ws1 = AnalysisByAirCarrier(package, req);
        var ws2 = Summary(package, req);

        var fileStream = new MemoryStream();
        package.SaveAs(fileStream);
        fileStream.Position = 0;
        var fsr = new FileStreamResult(fileStream, contentType);
        fsr.FileDownloadName = fileDownloadName;

        return fsr;
    }
    catch (Exception ex)
    {
        _logger.Error("Error ExportReports", ex);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想在不同选项卡中的同一文件中加入ws1和ws2.

注意:ws1和ws2是ExcelWorksheet对象

任何的想法??

谢谢.

c# excel epplus

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

更新服务引用后,Project不会生成

更新服务引用后,我收到以下错误构建我的项目:

不包含'DefaultResolveType'的定义

在自动生成的Reference.cs上抛出错误,但DefaultResolveType方法应该在生成的类中,因为它是从'this'关键字调用的.自上次成功构建以来,数据服务没有更改,客户端代码也没有更改.

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Services.Design", "1.0.0")]

protected global::System.Type ResolveTypeFromName(string typeName)
{
    global::System.Type resolvedType = this.DefaultResolveType(typeName, "Microsoft.Crm.Sdk.Data.Services", "ITF.DataAccessLayer.CRM.CrmAccessService");
    if ((resolvedType != null))
    {
        return resolvedType;
    }

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

.net c# wcf service-reference

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

用枚举初始化字典,名称在当前上下文中不存在

我正在尝试使用字符串作为键并使用枚举作为值来创建字典。码:

private enum Continent { Africa, Antarctica, Asia, Australia, Europe, NorthAmerica, SouthAmerica }

static void DemoDictionary()
{
    Console.WriteLine("\n\nDictionary Demo: (rivers)");
    Console.WriteLine("=========================\n");
    Dictionary<string, Continent> rivers = new Dictionary<string, Continent>()
    {
        {"Nile", Africa},
        {"Amazon", SouthAmerica},
        {"Danube", Europe}
    };
}
Run Code Online (Sandbox Code Playgroud)

所有的大陆名称都显示the name does not exist in the current context,但我不确定为什么。私有枚举和静态Dictionary方法需要保持不变,因此我需要解决此问题。

c# enums dictionary initialization

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

仅在焦点输出字段后才调用$ scope.watch函数

我刚接触角度和即时寻找一种调用函数的方法,目前在每次更改后调用,只有在焦点超出该字段之后.这个函数的目的是检查用户是否在某些情况下更改了数据,<td>并且只有在他更改了数据函数时才应该执行.问题是现在每个按键都调用该函数,所以如果使用将2个字符添加到字符串中,<td>它将执行两次.

这是我的表:

<tbody ng-repeat="(user_id,script_id) in data">
    <tr ng-repeat="(script_id, cron_format) in script_id">
        <td class="userName">{{user(user_id)}}</td>
        <td class="scriptName">{{script(script_id)}}</td>
        <td class="cronFormat"><input type="text" ng-model="cron_format" ng-change="saveCron(user_id,script_id,cron_format)"/></td>
    </tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)

这是功能:

$scope.$watch('cron_format',function(x,old){
    if(x!=old){
    }
});

$scope.saveCron = function(userId,scriptId,cronFormat){

   $.post("updateCronChange.php",
        "user_id="+userId+"&script_id="+scriptId+"&cron_format="+cronFormat, 
         function(data){
        //inside post
            alert('cron format changed to:'+cronFormat);
   });
}
Run Code Online (Sandbox Code Playgroud)

任何有角度的方式我只能在焦点离开字段(cron_format)之后调用saveCron()?

javascript angularjs

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

安全string.Format对象C#

我有一段时间以来第一次使用C#,我有一行这样的代码.

SQL = string.Format("PageName = '{0}'", bp.CommandArgument);
Run Code Online (Sandbox Code Playgroud)

我需要知道如何从任何SQL注入保护对象"bp.CommandArgument".谢谢.

c# sql asp.net security

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

无法在C#中隐式转换类型'System.Collections.Generic.List &lt;AnonymousType#1&gt;

嗨,我是编程新手,请您帮助我:

我在“ To.List()”中遇到错误,错误1无法将类型“ System.Collections.Generic.List”隐式转换为“ System.Collections.Generic.List”

我的代码是:

List<IncByYrMonthModel> GroupedList = (from p in incidentsViewModel
                                       group p by new 
                                       { 
                                           month = p.DateClosed.Value.Month, 
                                           year = p.DateClosed.Value.Year 
                                       } into d
                                       select new 
                                       {
                                           d.Key.month, 
                                           d.Key.year, 
                                           count = d.Count() 
                                        }).ToList();
return GroupedList;
Run Code Online (Sandbox Code Playgroud)

我的模特是:

public class IncByYrMonthModel
{
    public string Year { get; set; }
    public string Month { get; set; }
    public string Total { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

更新的代码

public List<IncByYrMonthModel> GetYrMonth2(HttpSessionStateBase session, int id, int _StrYear)
{
    List<IncidentsModel> incidentsViewModel = ViewModelService.Fetch<List<IncidentsModel>>(session, id); …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

C#原始静默溢出 - CLR通过c#

我正在通过C#由Jeffrey Richter阅读CLR,在第115页上有一个由基元上的算术运算产生溢出的例子.有人可以解释一下吗?

Byte b = 100;
b = (Byte) (b+200); // b now contains 44 (or 2C in Hex).
Run Code Online (Sandbox Code Playgroud)

我知道应该有溢出,因为byte是无符号的8位值,但为什么它的值等于44?

.net c# byte

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