更确切地说 - 如何以标准方式做到这一点?
我喜欢我的程序引起的VS跟踪异常的方式,因此当从VS运行它时,我没有理由使用我自己的机制来处理和显示异常.当然,当程序作为独立应用程序执行时,我必须依赖我的异常处理程序.
我知道,我可以在VS中定义一个参数来运行程序,这样可以识别这是否是VS运行,但我正在寻找标准的东西.也许VS设置一个标志,表明这是VS运行?
var obj = {
'51' : { 'name':'name1'},
'66' : { 'name':'name2'},
'58' : { 'name':'name3'}
};
$(function() {
s = '';
$.each(obj, function(k, v) {
s += ' '+k;
});
alert(s);
});
Run Code Online (Sandbox Code Playgroud)
在IE和Firefox中它是51 66 58,但在Opera和Chrome中它是51 58 66为什么Jquery.each()按照歌曲中的键排序,Chrome?我该怎么做才能保持原生秩序?
ps如果数组键是一个字符串,结果51j 66j 58j也许opera和chrome尝试将键转换为整数,这是可能的
var obj = {
"51j" : { "name":"name1"},
"66j" : { "name":"name2"},
"58j" : { "name":"name3"}
};
Run Code Online (Sandbox Code Playgroud) (与PropertyInfo SetValue和nulls相关)
如果我有public class Thing { public int X; },a Thing o和a FieldInfo fi指向该X字段,为什么打电话合法fi.SetValue(o, null)?运行时将字段X设置为零,即default(int)不是抱怨a ValueType不能设置为null.
有没有人知道这种行为背后的设计选择,至少从C#中违背了我最不惊讶的原则?
我发现findall(r'(ab)+', "ababababab") 只能匹配["ab"]
>>> re.findall(r'(ab)+', "ababababab")
['ab']
Run Code Online (Sandbox Code Playgroud)
我只知道使用r'(?:ab)+'可以匹配所有的字符
>>> re.findall(r'(?:ab)+', "ababababab")
['ababababab']
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
对不起,我可能不会清楚地说出我的问题
(?:ab)将'ab'作为一个整体,让我们做c = ab,所以c + = ababab ....
所以这很明显
>>> re.findall(r'(?:ab)+', "ababababab") <br>
['ababababab']
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么会发生这种情况:
>>> match=re.search(r'(ab)+', "ababababab") <br>
>>> match.group()<br>
'ababababab'
Run Code Online (Sandbox Code Playgroud) 这真让我抓狂.我有一个DataGrid,它有一个DataGridComboBoxColumn,我希望用户可以使用它来进行选择.这是我网格的基本轮廓.
<DataGrid ItemsSource="{Binding GoalList}" DockPanel.Dock="Bottom" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridComboBoxColumn ItemsSource="{Binding LifeAreaList}" Header="Life Area"/>
<DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
DataGrid绑定到Goal类型的对象集合.每个目标都有一个LifeArea类型的属性.每个LifeArea都具有LifeAreaId和Name属性.
数据上下文包含一个可观察的目标集合:目标列表和生命区域列表:LifeAreaList.我希望用户能够为目标选择不同的生活区域.生命区域的名称也需要是显示的值.
编辑
解决方案是必须将DataGridComboBoxColumn的ItemsSource设置为静态资源.另一种选择是通过代码设置ItemsSource.
最后我有:
<DataGridComboBoxColumn x:Name="_lifeAreaComboBoxColumn" SelectedItemBinding="{Binding LifeArea}" DisplayMemberPath="Name" Header="Life Area">
Run Code Online (Sandbox Code Playgroud)
在后面的代码我设置ItemsSource:
_lifeAreaComboBoxColumn.ItemsSource = LifeAreaDAL.GetLifeAreas();
Run Code Online (Sandbox Code Playgroud)
当我有机会将其转换为StaticResource时.
我已经创建了一个将文本框值转换为日期的函数.我想将转换后的日期存储在我的业务对象中的日期时间字段中,只有日期而不是时间格式(yyyy-MM-dd)
我的功能是返回日期和时间
public static DateTime ExtractDate(string myDate)
{
DateTime result = DateTime.MinValue;
if (myDate != null)
{
try
{
result=DateTime.Parse(myDate, new System.Globalization.CultureInfo("en-CA", true), System.Globalization.DateTimeStyles.AdjustToUniversal).ToString("yyyy-MM-dd");
}
catch (Exception)
{
throw new ApplicationException("DateTime conversion error");
}
}
return (result.Date);
}
Run Code Online (Sandbox Code Playgroud) 我需要根据它的属性排序一些元素.举个例子:
<div id="sort">
<div n="1"></div>
<div n="2"></div>
<div n="3"></div>
<div n="4"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
和array_num
{3, 2, 1, 4}
Run Code Online (Sandbox Code Playgroud)
伪代码:
$('#sort').sort(array_num, 'n');
Run Code Online (Sandbox Code Playgroud)
结果将是:
<div id="sort">
<div n="3"></div>
<div n="2"></div>
<div n="1"></div>
<div n="4"></div>
</div>
Run Code Online (Sandbox Code Playgroud) 试图了解这是什么IConnectionPoint以及如何连接到IConnectionPointContainer,IEnumConnectionPoints,IEnumConnections和EventHandling.
阅读MSDN和CodeProject中的artcicles,它解释了其他方法,如:QueryInterface()和其他方法.
我无法弄清楚所有这些东西(IConnectionPointContainer,IEnumConnectionPoints,IEnumConnections)是如何相互关联和事件处理.
我只想创建一个simpleClient,它将触发COM对象中的事件.
如果有任何文章或代码片段可以解释事物如何通过简单和小块代码相互关联将是有帮助的.
值得一提的是我最近开始在C开发,一个初学者.
编辑@sharptooth
对于线" typically your client will receive events and the COM object will trigger those events. "
从许多文章中,我理解的是当我们在那时使用连接点时,
the client exposes a set of methods that the server uses.
我只是概述来自TechRepublich的文章的一部分:
客户端服务器与接收源
因此,在标准客户端 - 服务器系统中使用COM进行正常编程和使用连接点之间的主要区别在于,在标准客户端 - 服务器情况下,服务器公开客户端使用的方法列表,并且在连接点情况下,客户端公开服务器使用的一组方法.
我有一个简单的mysql_query,我想编码results(title= > $title, price => $price etc)在json中.
$sql = mysql_query("SELECT * FROM item_details WHERE posting_id='$item_number'");
while($row = mysql_fetch_array($sql))
{
$title = base64_decode($row['title']);
$price = $row['price'];
$seller_user = $row['user'];
}
我有一个net.tcp WCF服务,我希望操作系统选择它应该监听的端口.所以我在我的URI中将端口设置为0,并netstat确认操作系统已经选择了5000范围内的端口.
如何在服务流程中找到代码中已选择的实际端口?
一些代码显示我尝试过的内容:
Type serviceType = ...;
Uri address = new Uri("net.tcp://0.0.0.0:0/Service/");
ServiceHost serviceHost = new ServiceHost(serviceType, address);
ServiceEndpoint endPoint = serviceHost.AddServiceEndpoint(type, binding, "");
int port1 = endPoint.ListenUri.Port; // returns 0
int port2 = serviceHost.BaseAddresses.First().Port; // also returns 0
Run Code Online (Sandbox Code Playgroud)