小编psj*_*j01的帖子

为什么在子类中实现抽象方法时需要在抽象方法前加上 override 关键字?

当我们创建一个从抽象类继承的类并且当我们实现继承的抽象类时,为什么我们必须使用 override 关键字?

public abstract class Person
{
    public Person()
    {

    }

    protected virtual void Greet()
    {
        // code
    }

    protected abstract void SayHello();
}

public class Employee : Person
{
    protected override void SayHello() // Why is override keyword necessary here?
    {
        throw new NotImplementedException();
    }

    protected override void Greet()
    {
        base.Greet();
    }
}
Run Code Online (Sandbox Code Playgroud)

由于该方法在其父类中被声明为抽象的,它在父类中没有任何实现,那么为什么这里需要关键字 override 呢?

c#

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

app.component.css中的CSS样式未应用于选项卡主体内容

你能告诉我为什么填充没有在这里应用,即使我在我的app.component.css文件中将padding-top设置为20px.如果我在styles.css文件中设置它将会工作.当我将css属性移动到app.component.css文件时,不确定它为什么不起作用.

app.component.ts文件:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

}
Run Code Online (Sandbox Code Playgroud)

app.component.html文件:

<mat-tab-group class="redThis">
    <mat-tab label="Tab 1">Content 1</mat-tab>
    <mat-tab label="Tab 2">Content 2</mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)

app.component.css文件

.mat-tab-body-content{
    padding-top:20px;
}
Run Code Online (Sandbox Code Playgroud)

angular

7
推荐指数
2
解决办法
7773
查看次数

HostAuthenticationFilter 有什么作用?

有人可以解释一下这两行代码在我的 WebApiConfig.cs 文件的 Register() 方法中的含义。

// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
Run Code Online (Sandbox Code Playgroud)

我假设它添加了 HostAuthentication 应用程序。但即使我没有在我的请求中传递不记名令牌,我仍然能够获取数据。那么添加这个过滤器有什么意义呢?

c# asp.net-web-api owin

7
推荐指数
1
解决办法
3092
查看次数

为什么C#中的Int32结构的MinValue在其前面有两个减号?

当我右键单击int我的代码并选择"转到定义"时,Visual Studio会打开一个名为"Int32 [来自元数据]"的文件.该文件包含以下行:

public const Int32 MinValue = --2147483648;
Run Code Online (Sandbox Code Playgroud)

双重标志是什么意思?

在此输入图像描述


我正在运行Visual Studio 15.8.4.根据评论中的信息,这在Visual Studio 2017的所有版本上都不可重现.

c# visual-studio

7
推荐指数
1
解决办法
287
查看次数

在批处理结束时检测到不可提交的事务。事务回滚

我有一个存储过程,我使用事务从 ac# 代码调用它。当我在 C#(它是一个控制台应用程序)中运行代码时,我没有从 catch 块中获取结果,而是抛出了一个异常,说:

在批处理结束时检测到不可提交的事务。事务回滚。

C#代码:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace app1
{
    class Program
    {
        static void Main(string[] args)
        {
            string res = "";
            string resDesc = "";

            res = WriteToDB(1,out resDesc);

            Console.WriteLine(res);
            Console.WriteLine(resDesc);


            Console.Read();
        }

        public static string WriteToDB(int val, out string resultDesc)
        {
            resultDesc = "";
            string result = "";
            string connectionString = ConfigurationManager.ConnectionStrings["SqlAppConnection"].ConnectionString;
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction("transcation1");
                try
                {
                    using (SqlCommand cmd …
Run Code Online (Sandbox Code Playgroud)

c# sql t-sql sql-server

7
推荐指数
1
解决办法
9544
查看次数

角度路由 - 路径顺序重要吗?

app.module.ts 文件中列出的路径顺序重要吗?例如...

   RouterModule.forRoot([
      {path:'',component:HomeComponent},
      {path:'followers',component:GithubFollowersComponent},
      {path:'followers/:username/:userid',component:GithubProfileComponent},
      {path:'posts',component:PostsComponent},
      {path:'**',component:NotFoundComponent}
    ])
Run Code Online (Sandbox Code Playgroud)

对比..

  RouterModule.forRoot([
      {path:'',component:HomeComponent},
      {path:'followers/:username/:userid',component:GithubProfileComponent},
      {path:'followers',component:GithubFollowersComponent},
      {path:'posts',component:PostsComponent},
      {path:'**',component:NotFoundComponent}
    ])
Run Code Online (Sandbox Code Playgroud)

我正在看一个教程,它说顺序很重要..但我尝试了两种方法,它们似乎都按预期工作......

如果我将通配符路径( ** )移到顶部,那么是的,我确实注意到了差异。但是对于其他人来说,顺序根本不重要吗?还是我在这里遗漏了什么?....

angular-routing angular

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

&lt;a&gt; 标记上的道具“组件”的值无效

我收到一条错误消息,指出标签上的 prop 'component' 值无效。

下面是我的组件中的代码。

<Link to="/posts" component={Posts}>
    See Posts
</Link>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

这个错误是什么意思?

reactjs

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

反应中的延迟加载 - 组件未加载

有人可以解释为什么我的懒加载组件永远不会加载吗?

所看到的只是消息加载...在屏幕上...并且没有错误。

下面是我的代码:

import React, { Component, lazy, Suspense } from "react";
import "./App.css";
//const Mycomp = lazy(() => import("./components/myComp"));
const Mycomp = lazy(() => {
  let x = new Promise(
    () => {
      import("./components/myComp");
    },
    e => {
      console.log(e);
    }
  );
  return x;
});

class App extends Component {
  sayHi = () => {
    console.log("supa");
  };

  render() {
    return (
      <Suspense fallback={<div> loading...</div>}>
        <div className="App">
          <header className="App-header">
            <Mycomp />
            <input type="button" value="sayHi" onClick={this.sayHi} />
          </header>
        </div>
      </Suspense>
    );
  } …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

表单发布时获取 HTTP ERROR 400

我有一个 asp.net core razor 页面,其中有一个简单的表单,要求提供用户电子邮件地址和提交按钮。当我输入电子邮件并单击提交按钮时,我总是收到 400 错误

HTTP 错误 400

我不确定我在这里做错了什么。我尝试在 OnPost 方法中放置一个断点,但我什至没有达到那个点。

下面是我的代码:

好人.cshtml

@page
@model WebApplication1.Pages.HomieModel
@{
    ViewData["Title"] = "Homie";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>Homie</h1>

<form method="post">
    <input type="email" name="emailaddress">
    <input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

好人.cshtml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace WebApplication1.Pages
{
    public class HomieModel : PageModel
    {
        public void OnGet(string n)
        {
        }

        public void OnPost()
        {
            var emailAddress = Request.Form["emailaddress"];
            // do something with emailAddress
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

错误信息(屏幕截图): 在此处输入图片说明

c# asp.net-core razor-pages

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

ipywidgets 按钮 onclick 事件不会引发 onclick 方法

import ipywidgets as widgets

button = widgets.Button(description="Click Me!")
output = widgets.Output()

display(button, output)

def on_button_clicked():
    print("button clicked")

button.on_click(on_button_clicked)
Run Code Online (Sandbox Code Playgroud)

该按钮出现了..但是当我单击该按钮时,我希望看到“已单击按钮”消息出现。但这并没有发生。

我在这里缺少什么吗?
我正在使用 vscode 来运行我的 jupyter 笔记本。

python visual-studio-code ipywidgets

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