如果我有一个返回某些东西的方法,比如
public DataTable ReturnSomething()
{
try
{
//logic here
return ds.Tables[0];
}
catch (Exception e)
{
ErrorString=e.Message;
}
}
Run Code Online (Sandbox Code Playgroud)
这会产生编译器错误,显然是因为catch{}块不返回任何内容.
所以当我有返回值的方法时,我不使用try-catch块,这是一种不好的做法.如果有错误,我想将错误字符串设置为该错误.但是我还需要一个返回值.建议吗?
在下面的c#代码中,当它不再有用时,如何摆脱它们?是自动照顾,还是我需要做某事?
public void Test()
{
object MyObject = new object();
... code ...
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试为将在MSN Messenger上运行的C#应用程序创建文本颜色.我正在排队等待所有事情.
这是我想要的输出示例:
1) Pizza Hut 123 Fake St.
2) Domino's Pizza 123 Fake St.
3) The Cheesecake Cafe 123 Fake St.
4) Capital Pizza & Steakhouse 123 Fake St.
5) Funky Pickle Pizza 123 Fake St.
6) Boston Pizza 123 Fake St.
7) Rose Bowl Rouge Lounge 123 Fake St.
8) Royal Pizza 123 Fake St.
9) A Columbus Pizza & Donair Inc 123 Fake St.
Run Code Online (Sandbox Code Playgroud)
但因为它是一个可变宽度的字体,它显示如下:
1) Pizza Hut 123 Fake St.
2) Domino's Pizza 123 Fake St. …Run Code Online (Sandbox Code Playgroud) 我在ZendFramework 1.11.2中使用Doctrine 2作为ORM的双向OneToMany关系.
注意:Doctrine没有创建数据库表.数据库是MySQL.
出于某种原因,当我持久化并将新的链接实体刷新到链接表(见下文)时,外键字段(container_id)被设置为NULL.但是,如果从'ManyToOne(targetEntity ="Shepherd\Navigation\Domain\Container\Model",inversedBy ="links")'行中删除'@'符号,则正确填充外键字段.
由于在删除"@"符号时将实体正确添加到数据库中,因此某处的OneToMany关系出现问题.
例如,如果我有一个名为$ link的链接模型(请参阅下面的伪代码)...
$link (Shepherd\Navigation\Domain\Link\Model)
{
id: '' // auto generated value
cid: 23 // the foreign key value
label: test
uri: test.com
... // other values not listed here for brevity
}
Run Code Online (Sandbox Code Playgroud)
...当保持新链接模型并刷新实体管理器时,链接(shepherd_navigation_link)表中新插入的行的container_id(外键)值为NULL.
$em // Assume $em is the Entity Manager
$em->persist($link);
$em->flush();
// The container_id in the newly added row in the
// link table (shepherd_navigation_link) is NULL
Run Code Online (Sandbox Code Playgroud)
链接表架构:
CREATE TABLE `shepherd_navigation_link` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`container_id` int(10) …Run Code Online (Sandbox Code Playgroud) 假设我们有一个二进制协议,字段网络有序(大端).
struct msg1
{
int32 a;
int16 b;
uint32 c
}
Run Code Online (Sandbox Code Playgroud)
而不是将网络缓冲区复制到我的msg1,然后使用"networkToHost"函数来读取msg1
我将msg1重新排列/反向
struct msg1
{
uint32 c
int16 b;
int32 a;
}
Run Code Online (Sandbox Code Playgroud)
并简单地从网络缓冲区执行反向复制以创建msg1.在这种情况下,不需要networkToHost功能.这种习惯用法在大端机器上不起作用,但对我来说这不是问题.除此之外,我还有其他任何缺点吗?
谢谢
PS为上面我们强制严格对齐(#pragma pack(1)等)
在Firefox中,您只需调用:
myInputTextField.selectionStart或myInputTextField.selectionEnd
获取输入框中所选文本的第一个和最后一个索引.
在IE中,我知道你可以调用document.selection.createRange()来调整选择.然而,对于我的生活,我没有找到任何代表选择中的字符偏移的值.
我错过了什么吗?有没有办法在IE中获得相同的价值?
谢谢!
亚历克斯
我已经开始学习trello api并尝试trello api client.js并根据trello.com上的示例开发基本应用程序.我在下面的链接上粘贴代码
http://jsfiddle.net/Ezyw4/2/它无法正常工作.我的代码中是否有任何错误.提前致谢!
我正在玩Trello API,我正在慢慢掌握它.我被困在一块,我设法在一个speicifc列表中创建一张新卡,但我想解析我从"createCard"调用得到的响应,例如获取新卡的ID.
这是我的Trello创建卡片帖子:
Trello.post("cards", { name: "Card Created from MVC", desc: "This is the description of the card.", idList: "??????????" }).done(onCardCreated());
Run Code Online (Sandbox Code Playgroud)
idList由于安全原因,我省略了真正的价值.
我可以在我的Trello板上立即看到该卡.我通过此调用得到的响应如下所示:
jQuery1510518084118841216_1327764237952({"id":"????","name":"Card Created from MVC","desc":........)
Run Code Online (Sandbox Code Playgroud)
我期待看到JSON返回喜欢这个:
{"id":"????","name":"Card Created from MVC","desc":....}
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,JSON就是这个jQuery1510518084118841216_1327764237952东西.
有些人可以告诉我jQuery的用途是什么,以及如何获取其中的JSON数据?
在.net 3.5
尝试ThreadPool.QueueUserWorkItem(a=> {Work()});在ThreadPool没有可用线程时导致BeginInvoke锁定.
void Work()
{
Action executor = () = { DoSomething(); };
IAsyncResult result = executor.BeginInvoke(null, null);
using (WaitHandle hWait = result.AsyncWaitHandle)
{
if (hWait.WaitOne(timeoutMilliseconds))
{
executor.EndInvoke(result);
}
else
{ throw new ImDyingException(); }
}
}
Run Code Online (Sandbox Code Playgroud)
如何使BeginInvoke使用非池化线程?
我一直在尝试获取一个模板,将字符串中的字符转换为大写字母.
我需要在整个程序中多次这样做.
所以我会使用一个模板.
template <string theString>
string strUpper( string theString )
{
int myLength = theString.length();
for( int sIndex=0; sIndex < myLength; sIndex++ )
{
if ( 97 <= theString[sIndex] && theString[sIndex] <= 122 )
{
theString[sIndex] -= 32;
}
}
return theString;
}
Run Code Online (Sandbox Code Playgroud)
现在只有模板有效!有什么建议?'string'标识符应该是立即标志.