我有一个基类和两个派生类:
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 关键字。
如何解决这个问题?
在项目定义中使用 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
语句的情况下解决这个问题?
我有字符串"00264A7BC"
,我想将其显示为"00 264 A7 BC"
.
所以,2个字母+空格+ 3个字母+空格+2个字母+空格+2个字母.
我在尝试,ToString
但它似乎没有这样的选择.
我怎样才能做到这一点?
我在页面上有一个图像和一个带有信息文本代码笔示例的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信息中的锚点位于右上角.我怎样才能做到这一点?
我有以下课程:
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表达式检查该人在同一位置是否在两个列表中具有相同的名称和年龄?我想检查所有职位.
我有以下代码:
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?
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) 我有以下字符串数组:
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表达式一步到位.
这可能吗?
我有以下字符串扩展名:
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
api ×1
api-design ×1
arrays ×1
asp.net-core ×1
css ×1
html ×1
inheritance ×1
jquery ×1
string ×1