且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有办法避免这种混乱?

更新时间:2021-08-18 00:22:08

是的,把乱七八糟的东西放在某处。

public int ToInt32(对象值)

{

试试

{

返回Convert.ToInt32(价值);

}

catch {}

}


" C#Learner" < CS **** @ learner.here>在消息中写道

新闻:uT ************** @ TK2MSFTNGP10.phx.gbl ...
Yes, put the mess in a function somewhere.

public int ToInt32(object value)
{
try
{
return Convert.ToInt32(value);
}
catch { }
}

"C# Learner" <cs****@learner.here> wrote in message
news:uT**************@TK2MSFTNGP10.phx.gbl...
有没有办法避免下面的混乱?

int i = 0;
if(someString!= null){
尝试{
i = Int32.Parse(someString);
} catch(FormatException){

}


更具体地说,有没有办法避免丑陋的空捕获声明?
Is there a way to avoid the following mess?

int i = 0;
if (someString != null) {
try {
i = Int32.Parse(someString);
} catch (FormatException) {

}
}

More specifically, is there a way of avoiding the ugly empty catch
statement?



Michael Culley写道:
Michael Culley wrote:
是的,把乱七八糟的东西放在某处。

public int ToInt32(对象值)
{
尝试
返回Convert.ToInt32(value);
}
catch {}
}
Yes, put the mess in a function somewhere.

public int ToInt32(object value)
{
try
{
return Convert.ToInt32(value);
}
catch { }
}




这不是一个讨厌的黑客。虽然?当然有更好的方法吗?!



Isn''t that a nasty "hack" though? Surely there''s a better way?!


不是真的,

与尝试使用Integer.ParseInt(字符串)没有什么不同)在

java。


我不记得如何在c ++中完成它但它可能是类似的。

我知道没有隐式转换因此它可能位于string.h

某处ctoi可能


Dave


C#学习者 &LT; CS **** @ learner.here&GT;在消息中写道

新闻:ea ************** @ TK2MSFTNGP11.phx.gbl ...
Not Really,
It is no different than if you tried to use Integer.ParseInt(string) in
java.

I dont remember off hand how it is done in c++ but it might be similar.
I know there is no implicit conversion so it is probably sitting in string.h
somewhere ctoi probably

Dave

"C# Learner" <cs****@learner.here> wrote in message
news:ea**************@TK2MSFTNGP11.phx.gbl...
Michael Culley写道:
Michael Culley wrote:
是的,把乱七八糟的东西放在某处。

public int ToInt32(对象值)
{
尝试
{
返回Convert.ToInt32(值);
}
抓住{}
}
Yes, put the mess in a function somewhere.

public int ToInt32(object value)
{
try
{
return Convert.ToInt32(value);
}
catch { }
}



这不是一个讨厌的 ;劈&QUOT;虽然?当然有更好的方法吗?!



Isn''t that a nasty "hack" though? Surely there''s a better way?!