小编Gab*_*nha的帖子

ASP.NET MVC Core DI注入服务列表

如何获得这样的新DI支持注入?

  public class Thing{

    public Thing(IList<IService> someServices) {

       ...
    }
  }

  public class ServiceA : IService { }
  public class ServiceB : IService { }
  public class ServiceB : IService { }

  public class Startup {
    ...

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddTransient<IService, ServiceA>()
                .AddTransient<IService, ServiceB>()
                .AddTransient<IService, ServiceC>();
    }
  }
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc

15
推荐指数
2
解决办法
2872
查看次数

清除推送列表时,清除通用列表堆栈

当我想在c#中做一些操作时,我有一点问题.我会举一个小例子.

Stack<List<HufmannLetter>> steps = new Stack<List<HufmannLetter>>();
List<HufmannLetter> letterList = new List<HufmannLetter>();    

while(true){

    letterList.Add("asd");
    letterList.Add("sad");

    steps.Push(letterList);
    letterlist.Clear();    
}
Run Code Online (Sandbox Code Playgroud)

在此代码中,我想将我的链表推送到堆栈而不是删除列表中的所有项目.当我清除列表时,我的堆栈的第一个索引消失,因为它通过引用传递.我错了吗?因为我不知道为什么会这样.

所以我使用pass by value方法.

Stack<List<HufmannLetter>> steps = new Stack<List<HufmannLetter>>();
List<HufmannLetter> letterList = new List<HufmannLetter>();

while(true) {

    letterList.Add("asd");
    letterList.Add("sad");

    List<HufmannLetter> tempLetterList = new List<HufmannLetter>(letterList);
    steps.Push(tempLetterList);
    letterlist.Clear();    
}
Run Code Online (Sandbox Code Playgroud)

这是解决问题的好方法吗?这样它工作,但可读性降低.你有什么建议我的?

谢谢...

c# parameter-passing generic-collections

6
推荐指数
1
解决办法
115
查看次数

将对象绑定到文本框c#

我是c#的新手,我正在寻找一种方法将我自己的对象的属性绑定到常规形式的文本框的值(每次输入值更改时重置对象的属性).

我已经阅读了一些信息,似乎只能对数据库对象进行此操作.你能给我一些额外的信息吗?

c# data-binding winforms

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

如何在UWP中显示加载图像?

我正在开发一个UWP应用程序.当用户点击任何控件时,如果该控件花费更长的时间来执行其任务,我想向用户显示操作需要很长时间的操作,请等待屏幕中央的图像.如何在UWP应用程序中执行此操作?

我想在这里,如果我是对的,我们的UWP正在研究单线程概念.
请给我你解决这个问题的建议.

c# win-universal-app

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

如何使用web.config appsettings中的键/值对创建JSON字符串?

我需要循环遍历web.config的app设置集合,并在JSON字符串中添加键值对.我正在使用JSON.Net.如何在for循环中准备JSON字符串?谢谢!

foreach (string key in ConfigurationManager.AppSettings)
{
    string value = ConfigurationManager.AppSettings[key];
}
Run Code Online (Sandbox Code Playgroud)

c# json.net

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