小编Mig*_*ura的帖子

派生类方法隐藏继承的成员

我有一个基类和两个派生类:

public abstract class BaseClass {

    public IEnumerable<Double> Inputs { get; protected set; }

    public BaseClass(IEnumerable<Double> inputs) {

        foreach (Double input in inputs)
            Compute(input);
    } 

    protected abstract Double Compute(Double input);
}

public abstract class DerivedClass1 : BaseClass {

    protected abstract Double Compute(Double input);
}

public class DerivedClass2 : DerivedClass1 {

    private override Double Compute(Double input) {

    // Compute implementation

    }
}
Run Code Online (Sandbox Code Playgroud)

我收到DerivedClass1 Compute方法错误:

“DerivedClass1.Compute(Double)”隐藏继承成员“BaseClass.Compute(Double)”。要使当前成员覆盖该实现,请添加 override 关键字。

如何解决这个问题?

c# inheritance

0
推荐指数
1
解决办法
61
查看次数

在 Net 6 中使用 &lt;Nullable&gt;enable&lt;/Nullable&gt; 时可能存在 null 引用参数

在项目定义中使用 Net6<Nullable>enable</Nullable>我有

public class Options {
  public Dictionary<String, String> Accounts { get; set; } = new Dictionary<String, String>();
}

Options options = new Options();

List<KeyValuePair<String, String>> parameters = new List<KeyValuePair<String, String>>();

parameters.Add(new KeyValuePair<String, String>("doc", options?.Accounts["doc"]));
Run Code Online (Sandbox Code Playgroud)

我收到错误“参数‘值’可能为空引用参数:”

options?.Accounts["doc"];
Run Code Online (Sandbox Code Playgroud)

我可以使用以下内容:

if (options.Accounts.ContainsKey("doc"))
  parameters..Add(new KeyValuePair<String, String>("to", options?.Accounts["doc"]!));
Run Code Online (Sandbox Code Playgroud)

我添加了if声明和!...

有没有其他方法可以在不使用该if语句的情况下解决这个问题?

c#

0
推荐指数
1
解决办法
1901
查看次数

将字符串"00264A7BC"显示为"00 264 A7 BC"

我有字符串"00264A7BC",我想将其显示为"00 264 A7 BC".

所以,2个字母+空格+ 3个字母+空格+2个字母+空格+2个字母.

我在尝试,ToString但它似乎没有这样的选择.

我怎样才能做到这一点?

c#

-1
推荐指数
1
解决办法
77
查看次数

创建图像叠加层

我在页面上有一个图像和一个带有信息文本代码笔示例的div .

<div>
  <img src="http://placehold.it/400x200"/>
  <div class="info">
    <a href="#">GO</a>
    <span>Title</span>    
    <p>Some information text</p>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我希望div信息不可见,当我将鼠标移到图像上时,div将显示在图像上,具有透明度,并且图像的宽度和高度完全相同.

而且我希望div信息中的锚点位于右上角.我怎样才能做到这一点?

html css jquery

-1
推荐指数
1
解决办法
721
查看次数

比较列表中所有位置的项目

我有以下课程:

public class Person {
   public String Name { get; set; }
   public Int32 Age { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我有两个人名单:

List<Person> a = service.GetPersons("a");
List<Person> b = service.GetPersons("b");
Run Code Online (Sandbox Code Playgroud)

列表大小相同.是否有可能使用Lambda表达式检查该人在同一位置是否在两个列表中具有相同的名称和年龄?我想检查所有职位.

c#

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

滴答中的日期时间差异不匹配

我有以下代码:

var a = (DateTime.Now.Subtract(DateTime.Now.AddTicks(8))).Ticks;
var b = (DateTime.Now - DateTime.Now.AddTicks(8)).Ticks;
Run Code Online (Sandbox Code Playgroud)

当我检查值时,我看到:

a = -78
b = -20
Run Code Online (Sandbox Code Playgroud)

怎么会?不应该都是-8?

c#

-1
推荐指数
1
解决办法
506
查看次数

Call an HTTP POST API with Flatten or not flatten body?

I am working on an API which can return a list of Users:

"users": [
  {
    "userId": 1,
    "name": "John Smith"
    "address": {
      "countryCode": "gb",
      "street": "Orford Street 20",
      "locality": "London"
    }
    "skills": [
      { "skillId": 1, "name": "design" },
      { "skillId": 2, "name": "logotype" }
    ]
  }
]
Run Code Online (Sandbox Code Playgroud)

Consider I need to create a User with address and skills.

Which body format is more commonly used? Something kind of flatten:

"users": [
  {
    "name": "John Smith"
    "addressCountryCode": "gb",
    "addressStreet": …
Run Code Online (Sandbox Code Playgroud)

api api-design asp.net-core

-1
推荐指数
1
解决办法
44
查看次数

字符串数组.选择

我有以下字符串数组:

var array1 = new String[] { "A", "B", "C", "D" }

var array2 = new String[] { "B", "D" }
Run Code Online (Sandbox Code Playgroud)

我需要做以下事情:

1)找到array2中的项目,它在array1中显示为firts(在这种情况下为B);

2)获取(1)中的项目以及在array1中出现的所有其他项目.

所以在这种情况下我会得到:

var array3 = new String[] { "B", "C", "D" }
Run Code Online (Sandbox Code Playgroud)

我试图用一个lambda表达式一步到位.

这可能吗?

c# arrays string

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

将字符串扩展转换为Linq

我有以下字符串扩展名:

    public static int LineFromPos(this string S, int Pos)
    {
        int Res = 1;
        for (int i = 0; i < Pos; i++) {
            if (S[i] == '\n') {
                Res++; }
        }
        return Res;
    }
Run Code Online (Sandbox Code Playgroud)

是否可以使用linq将其转换为单个代码行?

c#

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

标签 统计

c# ×7

api ×1

api-design ×1

arrays ×1

asp.net-core ×1

css ×1

html ×1

inheritance ×1

jquery ×1

string ×1