我有一个ArrayList
的Test
对象,使用字符串作为等价检查.我希望能够用来List.contains()
检查列表是否包含使用某个字符串的对象.
只是:
Test a = new Test("a");
a.equals("a"); // True
List<Test> test = new ArrayList<Test>();
test.add(a);
test.contains("a"); // False!
Run Code Online (Sandbox Code Playgroud)
等于和散列函数:
@Override
public boolean equals(Object o) {
if (o == null) return false;
if (o == this) return true;
if (!(o instanceof Test)) {
return (o instanceof String) && (name.equals(o));
}
Test t = (Test)o;
return name.equals(t.GetName());
}
@Override
public int hashCode() {
return name.hashCode();
}
Run Code Online (Sandbox Code Playgroud)
我读到这是为了确保contains
自定义类的工作,它需要覆盖equals
.因此,当我equals
返回true时contains
返回false …
举一个简单的例子,这个:文本应该在一行中,但由于div的大小,它被分解为三行.如何在没有包装的情况下让文本溢出div?
HTML:
<div style="width: 20px;">Some text here</div>
Run Code Online (Sandbox Code Playgroud)
结果:
Some
text
here
Run Code Online (Sandbox Code Playgroud)
我要这个:
Some text here
Run Code Online (Sandbox Code Playgroud) 我使用 CRA 创建了一个打字稿应用程序,代码如下:
import { ReactComponent as Search } from './search.svg'
Run Code Online (Sandbox Code Playgroud)
它运行良好,现在我想将此代码剥离到 npm 包(库)中。我通过首先再次运行 CRA,然后删除所有看起来不相关的内容(例如公共文件夹)来创建此包。一个简化版本/dist
如下所示:
esm/
icon/
index.d.ts
index.js
index.d.ts
index.js
Run Code Online (Sandbox Code Playgroud)
这是原文icon/index.ts
:
/// <reference types="react-scripts" />
import { ReactComponent as Search } from './search.svg'
export const Icons = {
Search,
}
Run Code Online (Sandbox Code Playgroud)
这是编译后的icon/index.d.ts
:
/// <reference types="react" /> <-- Changed for some reason??
export declare const Icons: {
Search: import("react").FunctionComponent<import("react").SVGProps<SVGSVGElement> & {
title?: string | undefined;
}>;
};
Run Code Online (Sandbox Code Playgroud)
当我尝试运行使用该库的应用程序时,出现以下错误:
../dist/esm/common/icon/index.js Attempted import error:
'ReactComponent' is not …
Run Code Online (Sandbox Code Playgroud) 假设所有w,x,y和z都可以在列表A中.是否有快捷方式来检查它是否只包含x - 例如.没有否定其他变量?
w,x,y和z都是单个值(不是列表,元组等).
我有这个:
@Html.DropDownListFor(x => x.SelectedValue, new SelectList(Model.SomeList, "Value", "Text"))
Run Code Online (Sandbox Code Playgroud)
并希望它呈现为:
<select required>
<option>...</option>
...
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
有可能没有覆盖发生吗?例如:
class A:
def __init__(self, name):
self.name = name
class B(A):
def __init__(self, name):
A.__init__(self, name)
self.name = name + "yes"
Run Code Online (Sandbox Code Playgroud)
self.name
B类是否有任何方法可以独立于A类,或者是否必须使用不同的名称?
这个SqlBuilder:
var builder = new SqlBuilder();
var sql = builder.AddTemplate( /*...
Run Code Online (Sandbox Code Playgroud)
强烈的愚蠢的问题,但是,我该如何使用呢?我知道它在中Dapper.Contrib
,但是那using
句话还不够。using
我需要添加哪些参考或其他陈述?
我有这个:
<div class="style1 neg">
<input type="submit" value="blah" />
</div>
Run Code Online (Sandbox Code Playgroud)
和css:
.style1 {
float: left;
margin-top: 25px;
}
.style1 .neg {
margin-top: 0;
}
Run Code Online (Sandbox Code Playgroud)
我试图否定margin-top,但是当我在浏览器中检查元素时,'neg'样式似乎完全被忽略了.我该怎么做呢?
我有一些函数,其原型看起来像这样:
public void doThings(string sql, dynamic dParams);
它使用这些参数进行某种SQL查询.我没有写它,但我必须使用它.当我做这样的事情时它工作正常:
doThings("select * from SomeTable where myval1=@v1 and myval2=@v2",
new
{
v1 = new Dapper.DbString()
{
Value = "yay",
IsAnsi = true,
Length = 50
},
v2 = new Dapper.DbString()
{
Value = "really",
IsAnsi = true,
Length = 32
}
});
Run Code Online (Sandbox Code Playgroud)
但是当我第一次将动态参数放入ExpandoObject时:
dynamic dynParams = new ExpandoObject();
dynParams.v1 = new Dapper.DbString()
{
Value = "yay",
IsAnsi = true,
Length = 50
}
doThings("query here", dynParams);
Run Code Online (Sandbox Code Playgroud)
然后查询不返回任何结果.我不想打电话doThings()
和写new
块十倍十个不同的场景,我可能要查询myval2
或 …
我有一个这样的课:
public class SomeModel
{
public List<Item> Items { get; set; }
public SomeModel()
{
this.Items = new List<Item>();
}
}
Run Code Online (Sandbox Code Playgroud)
在Item
形式上可以有可变数量的s,零到多.我正在使用javascript在提交时动态追加隐藏的输入字段:
$("#container").children(".item").each(function (i) {
form.append('<input type="hidden" name="Items[' + i + '].Id" value="' + $(this).val() + '" />');
});
Run Code Online (Sandbox Code Playgroud)
但是,提交后,我收到此错误:
System.NotSupportedException: Collection is read-only.
Run Code Online (Sandbox Code Playgroud)
渲染的语法基本相同,一个我就会使用@Html.HiddenFor(model => model.Items[i].Id)
与model.Items
作为一个数组,而不是一个列表,并且工作正常.这里出了什么问题?
行动方法签名:
public ActionResult Post(SomeModel m)
{
Run Code Online (Sandbox Code Playgroud)