我在C#中撰写了一个方案,我希望将“(null)”改为“(null)”的例外情况。 例外的名称是什么?
EDIT: I m not sure I can show the full code... But I m sure you don t need the full code, so:
int num1 = Int32.Parse(number1.Text);
int num2 = Int32.Parse(number2.Text);
我在C#中撰写了一个方案,我希望将“(null)”改为“(null)”的例外情况。 例外的名称是什么?
EDIT: I m not sure I can show the full code... But I m sure you don t need the full code, so:
int num1 = Int32.Parse(number1.Text);
int num2 = Int32.Parse(number2.Text);
www.un.org/Depts/DGACM/index_spanish.htm 如果你能够避免,则不例外地制定法律!
您正在寻找的例外情况称为
但是,在你试图穿透的物体上,例如,先做<>TryParse的标记。
int value;
if(!int.TryParse("1", out value))
{
// You caught it without throwing an exception.
}
页: 1 如果教区失败的话。 为什么不使用int.TryParse?
作为旁观,找到例外情形的一个简单办法是予以处理。 当你遇到错误时,请你以例外名称。
公开静态插图
[......]
例外:
ArgumentNullException
: s is null.FormatException
: s is not in the correct format.
回答您的问题。 正如其他人已经提到的那样,也许你会问错问题,希望使用Int32.TryParse。
取决于您为转换而重新使用的方法。 例如,int.Parse
>将扔进ArgumentNullException
,OverflowException
。 dds 是ArgumentNullException
。 FormatException
当例外大火时,你可以发现这种火焰。 要做的聪明事情是处理这一案件,如果可能,就会向用户发出一个宽松的信息。
你也许会想获得<条码>System.InvalidCastException,尽管我认为这取决于你如何努力进行转换。
尽管如此,简单写成法典并尝试它是否更快捷? 具体来说,正如你已指明的how,你将进行转换。
只是审判。 该法典:
int.Parse("");
浏览格式。
例外是昂贵的。 你们应当使用TryParse。 如果转换工作失败,它将归还ool。
Convert. ToInt32没有将格式例外(“投射方式不符合正确格式”)排在无效指示上。 如果结果被否定,你可以使用。 (在空壳上still升)
string s = null;
int i = Convert.ToInt32(s);
但是,如果你预计会有一些人坐在盒子里,那么你要么使用TryParse(据建议),要么使用某种打字器告知用户他们需要进入数。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...