<div id="test"></div>
<script>
$(document).ready(function() {
alert($('#test').id);
});
</script>
Run Code Online (Sandbox Code Playgroud)
为什么上述工作没有,我该怎么办呢?
作为标题,我有一个已经填充150000条记录的现有表.我添加了一个Id列(当前为null).
我假设我可以运行查询以使用增量数填充此列,然后设置为主键并启用自动增量.这是正确的方法吗?如果是这样,我如何填写初始数字?
可能重复:
通过其描述属性查找枚举值
我有一个通用的扩展方法,它Description
从以下方式获取属性Enum
:
enum Animal
{
[Description("")]
NotSet = 0,
[Description("Giant Panda")]
GiantPanda = 1,
[Description("Lesser Spotted Anteater")]
LesserSpottedAnteater = 2
}
public static string GetDescription(this Enum value)
{
FieldInfo field = value.GetType().GetField(value.ToString());
DescriptionAttribute attribute
= Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute))
as DescriptionAttribute;
return attribute == null ? value.ToString() : attribute.Description;
}
Run Code Online (Sandbox Code Playgroud)
所以我可以......
string myAnimal = Animal.GiantPanda.GetDescription(); // = "Giant Panda"
Run Code Online (Sandbox Code Playgroud)
现在,我正试图在另一个方向上找出等效函数,比如......
Animal a = (Animal)Enum.GetValueFromDescription("Giant Panda", typeof(Animal));
Run Code Online (Sandbox Code Playgroud) 我有一个类似的数据结构
public DespatchGroup(DateTime despatchDate, List<Products> products);
Run Code Online (Sandbox Code Playgroud)
而我正在努力......
var list = new List<DespatchGroup>();
foreach (var group in dc.GetDespatchedProducts().GroupBy(i => i.DespatchDate))
{
// group.Values is not correct... how do I write this?
list.Add(new DespatchGroup(group.Key, group.Values);
}
Run Code Online (Sandbox Code Playgroud)
我显然不理解,IGrouping
因为我无法看到如何实际访问组内的数据记录!
我在寻找......
$(':input:not(readonly)') // all inputs which are not readonly
Run Code Online (Sandbox Code Playgroud)
但努力寻找语法.
有什么指针吗?谢谢
我有以下构造方法MemoryStream
从文件路径打开一个:
MemoryStream _ms;
public MyClass(string filePath)
{
byte[] docBytes = File.ReadAllBytes(filePath);
_ms = new MemoryStream();
_ms.Write(docBytes, 0, docBytes.Length);
}
Run Code Online (Sandbox Code Playgroud)
我需要更改它以接受Stream
而不是文件路径.什么是最简单/最有效的方法来MemoryStream
从Stream
对象获取?
如何解析边框宽度
style="border: solid 1px black;"
在jQuery/javascript?
$elem.css('border-width')
不这样做.
注意我需要解析css的宽度,因为元素可能是 display:none
谢谢
编辑我实际上并没有使用内联样式,我只是为了简单而编写它,因为我没有意识到存在任何行为差异.它似乎适用于内联样式,但仍然无法从应用的css类中获得任何值.
在尝试学习Unity时,我一直看到以下代码覆盖GetControllerInstance
MVC:
if(!typeof(IController).IsAssignableFrom(controllerType)) { ... }
Run Code Online (Sandbox Code Playgroud)
在我看来,这基本上是一种非常复杂的写作方式
if(controllerType is IController) { ... }
Run Code Online (Sandbox Code Playgroud)
我理解,存在之间的细微差别is
和IsAssignableFrom
,即IsAssignableFrom
不包括投转换,但我在努力了解实际情况下这种差别的含义.
什么时候选择IsAssignableFrom
结束有意义is
?它会有什么不同GetControllerExample
?
if (!typeof(IController).IsAssignableFrom(controllerType))
throw new ArgumentException(...);
return _container.Resolve(controllerType) as IController;
Run Code Online (Sandbox Code Playgroud) string s1;
string s2 = null;
if (s1 == null) // compile error
if (s2 == null) // ok
Run Code Online (Sandbox Code Playgroud)
我真的不明白为什么需要明确的赋值.什么是null变量和未赋值变量之间的区别?我总是假设运算符/编译器无论如何都将未分配的变量简单地赋值为null.如果它们不是空的,那么它们是什么?
我已经在这里回答了许多问题.但究竟是什么意思呢?
var test = new Dictionary<int, string>();
test.Add(0, "zero");
test.Add(1, "one");
test.Add(2, "two");
test.Add(3, "three");
Assert(test.ElementAt(2).Value == "two");
Run Code Online (Sandbox Code Playgroud)
上面的代码似乎按预期工作.那么字典被认为是无序的?在什么情况下上面的代码会失败?
c# ×6
.net ×3
jquery ×3
alter-table ×1
asp.net-mvc ×1
attributes ×1
casting ×1
css ×1
dictionary ×1
enums ×1
file-io ×1
igrouping ×1
javascript ×1
linq ×1
memorystream ×1
primary-key ×1
reflection ×1
sql-server ×1
stream ×1