我的需求是要求对一个数组进行操作,操作前需对参数数组进行判定,如果该数组长度为1或者所有数字都一样时则抛出一个自定义的异常,请各位高手指点迷津!!!(不考虑用程序逻辑判断)
用C#麻烦大侠写下给我参考下!非常感谢!
用C#麻烦大侠写下给我参考下!非常感谢!
解决方案 »
- 关于SerialPort类的读取问题
- 救命啊,如果获取客户端计算机信息,如CPU的ID号,硬盘,主板(是客户端的,不要服务器端的)
- 记事本状态栏上的行和列问题
- C#新手,关于bindingnavigator中添加一个SaveButton保存的问题?
- 流媒体播放
- 解码高手请进
- c#使用webbrowser和javascript交互的问题 困扰我快一个礼拜了 急死了 各位大哥帮忙啊
- 急需用c#来浏览大幅图像?
- 一个在调用文件时遇到的问题(知情者帮帮忙)
- 将发布的c#中文正式版有中文的msdn?微软会在以后出?
- 基类与派生类中有同名方法,如何对派生类实例调用基类方法?
- 对PictureBox控件如何开启中文输入法
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;namespace HKH.Exception
{
[Serializable]
public class HKHException : ApplicationException
{
/// <summary>
/// do not allow creation of exception with no message
/// </summary>
private HKHException()
{
} /// <summary>
/// Constructor takes problem message to be thrown
/// invokes constructor on ApplicationException
/// </summary>
public HKHException(string message)
:base(message)
{
} /// <summary>
/// Constructor takes problem message and caught exception
/// invokes constructor on ApplicationException
/// </summary>
public HKHException(string message, System.Exception ex)
:base(message, ex)
{
} protected HKHException(SerializationInfo si, StreamingContext sc)
: base(si, sc)
{
}
}}如果消息固定,可以考虑去掉部分构造
{
public ArrayException(string message):base(message)
{ }
}2、判断符合条件后,抛出自定义异常protected void Page_Load(object sender, EventArgs e)
{
int[] test = { 1, 1, 1, 2 };
if (test.Length == 1 || test.Distinct().Count() == 1)
throw new ArrayException("数据长度不能为1,或数据内数据都相同");
Response.Write("success");
}