我知道,Int32.MaxValue * Int32.MaxValue会产生一个大于的数字Int32; 但是,这句话不应该提出某种例外吗?
在做IF (X * Y > Z)所有事情的时候,我碰到了这个Int32.X并且Y足够大,你会得到一个虚假的价值X * Y.
为什么这样以及如何解决这个问题?除了把一切都投到了Int64.
我可能误解了正在发生的事情,但是我可以告诉我在使用时获取DOM元素而不是jQuery对象.each().
以下内容不适this用于DOM元素而不是jQuery对象
$("span[id$='_TotalItemCost']").each(function() {
var someText = this.text();
});
Run Code Online (Sandbox Code Playgroud)
修改为转换this为jQuery对象,一切都很好
$("span[id$='_TotalItemCost']").each(function() {
var someText = $(this).text();
});
Run Code Online (Sandbox Code Playgroud)
我的选择器有什么时髦吗?是jQuery的.each()文档错误的,它不是一个jQuery对象,而是一个DOM元素被退回.each()?
我想获得格林威治标准时间的当前时间戳; 任何想法如何做到这一点?
我设法得到gmt格式的字符串问题是我想将此字符串转换为等效的时间戳对象,即同一时间但作为时间戳对象
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date=new Date();
String s=sdf.format(date);
System.out.println("GMT: "+s);
//need to convert the string to equivalent timestamp object
Run Code Online (Sandbox Code Playgroud) 我的MSBuild命令行如下:
msbuild e:\code\myProject.csproj /p:Configuration=Debug /p:OutputPath=bin/Debug /p:Platform=x86 /p:PlatformTarget=x86
该项目在VS2010中的开发机器上构建良好,但不是上面的命令.我正在运行Win 7 64位.我收到一条错误消息,说我没有安装Silverlight 4 SDK,但我确实如此.我已经阅读了一些帖子,你必须设置Platform = x86但无济于事.以下是完整的错误消息:
Microsoft (R) Build Engine Version 4.0.30319.1 [Microsoft .NET Framework, Version 4.0.30319.1] Copyright (C) Microsoft Corporation 2007. All rights reserved. Build started 6/8/2010 4:03:38 PM. Project "E:\code\dashboards\MyProject2010\MyProject2010.Web\MyProject2010 .web.csproj" on node 1 (default targets). GenerateTargetFrameworkMonikerAttribute: Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output fi les are up-to-date with respect to the input files. CoreCompile: Skipping target "CoreCompile" because all output files are up-to-date with resp ect to the input files. …
我对在开发过程中使用SQLite作为数据库解决方案的可能性感到很兴奋,因此我可以专注于首先编写代码并使用NHibernate的ShemaExport功能在运行时动态生成db.但是,我遇到了一些问题,其中最重要的是,似乎SQLite要求我使用Int64作为我的主键(比如Int32或Guid).有没有办法解决?
注意:我应该指定这是在使用NHibernate的应用程序的上下文中.严格来说,不能在SQLite中使用INT数据类型创建表,但保存和检索数据时的行为似乎表明它是作为Int64存储和/或检索的.
我维护了一个安装在多个位置的产品,这些产品随意升级.在许多表中添加了唯一约束,但我不知道任何特定实例的名称是什么.我所知道的是具有唯一约束的表/列名对,我想编写一个脚本来删除这些列/表组合上的任何唯一约束.
这是SQL Server 2000及更高版本.在2000/2005/2008上运作的东西最好!
我应该使用Dictionary <string,string>而不是NameValueCollection的任何原因?
(在C#/ .NET Framework中)
选项1,使用NameValueCollection:
//enter values:
NameValueCollection nvc = new NameValueCollection()
{
{"key1", "value1"},
{"key2", "value2"},
{"key3", "value3"}
};
// retrieve values:
foreach(string key in nvc.AllKeys)
{
string value = nvc[key];
// do something
}
Run Code Online (Sandbox Code Playgroud)
选项2,使用Dictionary <string,string> ...
//enter values:
Dictionary<string, string> dict = new Dictionary<string, string>()
{
{"key1", "value1"},
{"key2", "value2"},
{"key3", "value3"}
};
// retrieve values:
foreach (KeyValuePair<string, string> kvp in dict)
{
string key = kvp.Key;
string val = kvp.Value;
// do …Run Code Online (Sandbox Code Playgroud) 我有一个满是地址的数据库,我需要得到lat和long,所以我想循环遍历它们并使用Google Geocode来更新我的数据库.我被困在如何解析JSOn结果以获得我需要的东西:
var address = "http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false";
var result = new System.Net.WebClient().DownloadString(address);
GoogleGeoCodeResponse test = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(result);
Run Code Online (Sandbox Code Playgroud)
我以为我可以简单地构建一个快速类并使用JSON.Net来反序列化结果,它有点工作但我想我在我的类结构上吹它:
public class GoogleGeoCodeResponse {
public string status { get; set; }
public geometry geometry { get; set; }
}
public class geometry {
public string location_type { get; set; }
public location location { get; set; }
}
public class location {
public string lat {get;set;}
public string lng {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
以下是从Google返回的内容示例:
{
"status": "OK",
"results": [ {
"types": [ "street_address" ],
"formatted_address": "1600 …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的数据模型:
public class Item {
private List<ItemAttribute> attributes;
// other stuff
}
public class ItemAttribute {
private String name;
private String value;
}
Run Code Online (Sandbox Code Playgroud)
(这显然简化了很多无关紧要的东西)
我想要做的是创建一个查询来询问具有一个或多个特定属性的所有项目,理想情况下使用任意AND和OR连接.现在我保持简单,只是试图实现AND案例.在伪SQL(或伪HQL,如果你愿意),它将是这样的:
select all items
where attributes contains(ItemAttribute(name="foo1", value="bar1"))
AND attributes contains(ItemAttribute(name="foo2", value="bar2"))
Run Code Online (Sandbox Code Playgroud)
Hibernate文档中的示例似乎没有解决这个特定的用例,但它似乎是一个相当普遍的用例.分离案例也很有用,特别是我可以指定一个可能的值列表,即
where attributes contains(ItemAttribute(name="foo", value="bar1"))
OR attributes contains(ItemAttribute(name="foo", value="bar2"))
-- etc.
Run Code Online (Sandbox Code Playgroud)
这是一个适用于单个属性的示例:
return getSession().createCriteria(Item.class)
.createAlias("itemAttributes", "ia")
.add(Restrictions.conjunction()
.add(Restrictions.eq("ia.name", "foo"))
.add(Restrictions.eq("ia.attributeValue", "bar")))
.list();
Run Code Online (Sandbox Code Playgroud)
学习如何做到这一点将大大有助于扩展我对Hibernate潜力的理解.:)
帮助一个人.似乎无法让装饰器与继承一起工作.将其分解为我的临时工作空间中最简单的小例子.仍然似乎无法让它工作.
class bar(object):
def __init__(self):
self.val = 4
def setVal(self,x):
self.val = x
def decor(self, func):
def increment(self, x):
return func( self, x ) + self.val
return increment
class foo(bar):
def __init__(self):
bar.__init__(self)
@decor
def add(self, x):
return x
Run Code Online (Sandbox Code Playgroud)
哎呀,名字"装饰"没有定义.
好的,怎么样@bar.decor?TypeError:必须使用bar实例作为第一个参数调用未绑定方法"decor"(获取函数实例)
好的,怎么样@self.decor?名称"self"未定义.
好的,怎么样@foo.decor?!名称"foo"未定义.
AaaaAAaAaaaarrrrgggg ...我做错了什么?
c# ×3
java ×2
.net ×1
collections ×1
constraints ×1
date ×1
decorator ×1
dictionary ×1
dom ×1
gmt ×1
google-maps ×1
hibernate ×1
inheritance ×1
int ×1
jquery ×1
json ×1
math ×1
msbuild ×1
python ×1
silverlight ×1
sql ×1
sql-server ×1
sqlite ×1
t-sql ×1