我的需求是要求对一个数组进行操作,操作前需对参数数组进行判定,如果该数组长度为1或者所有数字都一样时则抛出一个自定义的异常,请各位高手指点迷津!!!(不考虑用程序逻辑判断)
用C#麻烦大侠写下给我参考下!非常感谢!
用C#麻烦大侠写下给我参考下!非常感谢!
解决方案 »
- rdlc报表怎么做?
- 【求助】关于DataBindings在Format后,ConvertEventHandler不能触发的问题
- C# 安装包问题
- 一个可以输入的对话框 不知道是哪个命令引用出来
- 关于OleDbCommand的用法 实在是郁闷 “必须声明标量变量 "@bytes"。”
- 如何获得此字符串中的一部分
- 请问如何遍历一段IP地址啊
- mapx控件的鼠标移动事件在mapx控件的左半边不激发。。。。。。T_T
- 如何在C# Winform中实现类似百度搜索功能????要求如下
- 谁知道hotmail的pop3与smtp服务器名是什么?
- 基类与派生类中有同名方法,如何对派生类实例调用基类方法?
- 对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");
}