小编Mon*_*mer的帖子

我应该使用AddMvc或AddMvcCore进行ASP.NET Core MVC开发吗?

我正在从一本书中学习ASP.NET Core MVC,有问题的代码片段如下:

// CHAPTER 4 - ESSENTIAL C# FEATURES
namespace LanguageFeatures {

    public class Startup {

        public void ConfigureServices(IServiceCollection services) {
            services.AddMvc();
        }

        // etc.
Run Code Online (Sandbox Code Playgroud)

因为这本书是关于ASP.NET核心MVC而不是ASP.NET MVC,我认为我必须使用AddMvcCore()而不是AddMvc()如下:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvcCore(); // as opposed to:
    //services.AddMvc();
}
Run Code Online (Sandbox Code Playgroud)

我在这里做的是正确的吗?

c# asp.net-core-mvc

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

为什么Razor Pages是在Asp.net Core 2.0中创建Web UI的推荐方法?

学习新事物需要投入时间,空间和精力.我目前正在学习Asp.Net Core MVC 2.0.此ASP.NET核心教程概述指出:

Razor Pages是使用ASP.NET Core 2.0创建Web UI的推荐方法.

这个信息使我无法决定是否必须停止学习Asp.net Core MVC并开始学习Asp.net Core Razor Pages.

  • 为什么Razor Pages是在Asp.net Core 2.0中创建Web UI的推荐方法?

欢迎任何指示.

asp.net asp.net-core-mvc asp.net-core razor-pages asp.net-core-mvc-2.0

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

AddDbContext或AddDbContextPool

对于Asp.net核心应用程序,我们必须使用哪一个?AddDbContext还是AddDbContextPool?根据EF Core文档,AddDbContextPool提供高性能但默认的Asp.net Core项目模板使用AddDbContext.

entity-framework-core asp.net-core asp.net-core-2.0

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

如何在没有安装程序的情况下卸载MS .NET Core 1.0 RC2 VS 2015工具预览版1?

几个星期前我安装了

Microsoft .NET Core 1.0 RC2 Visual Studio 2015工具预览1

但是几天前发布了一个更新版本,所以我必须在安装新版本之前卸载当前版本.

当我单击Uninstall以下对话框时,

在此输入图像描述

卸载程序提示我提供安装程序.不幸的是,安装程序已被删除,我不知道我可以在哪里找到它.

我认为提示我们提供安装程序以进行卸载可能是一个非常糟糕的主意.顺便说一句,如何在没有安装程序的情况下卸载MS .NET Core 1.0 RC2 VS 2015 Tooling Preview 1?

visual-studio visual-studio-2015

22
推荐指数
1
解决办法
3802
查看次数

如何自动填充CreatedDate和ModifiedDate?

我正在学习ASP.NET核心MVC,我的模型是

namespace Joukyuu.Models
{
    public class Passage
    {
        public int PassageId { get; set; }
        public string Contents { get; set; }


        public DateTime CreatedDate { get; set; }
        public DateTime ModifiedDate { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

Passage表用于保存我写的段落.

脚本

  • Create视图只有一个字段Contents来输入一个段落. CreatedDate并且ModifiedDate必须由服务器自动设置为相等(使用UTC格式).

  • Edit视图只有一个字段Contents来编辑一个段落.ModifiedDate必须由服务器自动设置.

根据上述场景,我必须将哪些属性附加到CreatedDateModifiedDate属性以使它们由服务器自动填充?

c# entity-framework asp.net-core-mvc

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

如何有条件地定义lambda?

以下功能将在加载的图像上随机“撒盐”。为了提高性能,条件语句

uint j = rows == 1 ? 0 : randomRow(generator);
Run Code Online (Sandbox Code Playgroud)

不应在循环内。

相反,我想getJ在循环之前定义一个lambda 作为

auto getJ = rows == 1 ? []() {return 0; } : []() {return randomRow(generator); };
Run Code Online (Sandbox Code Playgroud)

但是,我的带有此lambda的代码无法使用以下红色弯曲文本进行编译:

在此处输入图片说明

如何有条件地定义这样的lambda?

void salt_(Mat mat, unsigned long long n)
{
    const uchar channels = mat.channels();
    uint cols = mat.cols;
    uint rows = mat.rows;

    if (mat.isContinuous())
    {
        cols *= rows;
        rows = 1;
    }

    default_random_engine generator;
    uniform_int_distribution<uint> randomRow(0, rows - 1);
    uniform_int_distribution<uint> randomCol(0, cols - 1);



    // auto …
Run Code Online (Sandbox Code Playgroud)

c++

10
推荐指数
1
解决办法
854
查看次数

我们什么时候需要 IOptions?

我正在 .Net Core 中学习 DI,但我不知道使用 .Net Core 的好处 IOptions

IOptions如果我们可以没有它,为什么我们需要它?

IOptions

interface IService
{
    void Print(string str);
}

class Service : IService
{
    readonly ServiceOption options;
    public Service(IOptions<ServiceOption> options) => this.options = options.Value;
    void Print(string str) => Console.WriteLine($"{str} with color : {options.Color}");
}

class ServiceOption
{
    public bool Color { get; set; }
} 

class Program
{
    static void Main()
    {
        using (ServiceProvider sp = RegisterServices())
        {
            //
        }
    }


    static ServiceProvider RegisterServices()
    {
        IServiceCollection isc = …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection

9
推荐指数
1
解决办法
1443
查看次数

RecyclerView概念如何在android上运行?

我使用RecyclerView和CardView从网站获取教程创建了一个基本应用程序.

应用程序工作正常,我有一些困惑.(我在这里显示我的整个代码)

混淆是代码如何逐步运作.所以请清楚我的概念.

我的应用程序的基本结构:

  1. 我已经创建了一个row_data_layout要绑定的xml文件recycler_view.
  2. 创建了一个Data类文件(这里我定义了我在App中使用的变量)
  3. 创建了一个适配器文件(这里我想清楚它是如何逐步地进行类调用以及为什么?).
  4. 数据绑定到RecyclerViewMainActivity文件

row_data_layout.xml 档案:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/CardView"
    android:paddingBottom="16dp"
    android:layout_marginBottom="16dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txt_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

数据类文件:

public class Data {
    public String Name;

    Data(String Name)
    {
        this.Name=Name;
    }
}
Run Code Online (Sandbox Code Playgroud)

Data_Adapter类文件:

public class Data_Adapter extends RecyclerView.Adapter<Data_Adapter.View_holder> {
    List<Data> list = Collections.emptyList();
    Context context;

    public Data_Adapter(List<Data> list, Context context) {
        this.list = list;
        this.context …
Run Code Online (Sandbox Code Playgroud)

android adapter android-cardview android-recyclerview

8
推荐指数
1
解决办法
8926
查看次数

如何使用1d数组列表初始化2d数组?

如何使用1d数组列表初始化2d数组?

void main()
{
    int a[] = { 1,2,3 };
    int b[] = { 4,5,6 };
    int array[][3] = { a,b };
}
Run Code Online (Sandbox Code Playgroud)

c++ arrays multidimensional-array

7
推荐指数
3
解决办法
193
查看次数

Thread.Join 与 Task.Wait

考虑以下代码。

线

static void Main(string[] args)
{
    Thread t = new Thread(Foo);
    t.Start();

    Console.WriteLine("Main ends.");
    //t.Join();
}

static void Foo()
{
    for (int x = 0; x < 1000000000; x++) ;

    Console.WriteLine("Foo ends.");
}
Run Code Online (Sandbox Code Playgroud)

任务

static void Main(string[] args)
{
    Task t = new Task (Foo);
    t.Start();

    Console.WriteLine("Main ends.");
    t.Wait();
}

static void Foo()
{
    for (int x = 0; x < 1000000000; x++) ;

    Console.WriteLine("Foo ends.");
}
Run Code Online (Sandbox Code Playgroud)

使用时Task,我们需要t.Wait()在主线程结束之前等待线程池线程完成,但使用时Thread,我们不需要t.Join得到相同的效果。

为什么t.Join() …

c# multithreading task

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