zoukankan      html  css  js  c++  java
  • 泛型的应用(转)

    在.net 2.0 以后引入了泛型的概念,支持泛型的对象有类、方法、接口等。这里只是一个泛型的简单(方法)的简单的示例。。。

    泛型函数
            #region 转换 Request 值为指字类型
            
    /// <summary>
            
    /// 转化 Request 值为指字类型
            
    /// </summary>
            
    /// <typeparam name="T">泛型</typeparam>
            
    /// <param name="param">参数</param>
            
    /// <param name="defaultValue">默认值</param>
            
    /// <param name="isRequestForm">是否表单参数(否为 url 中的参数)</param>
            
    /// <returns>T: 泛型</returns>
            public static T ConvertRequest<T>(string param, T defaultValue, bool isRequestForm)
            {
                
    string RequestStr = "";
                
    if (!isRequestForm)
                { RequestStr 
    = HttpContext.Current.Request.QueryString[param]; }
                
    else
                { RequestStr 
    = HttpContext.Current.Request.Form[param]; }

                
    if (RequestStr != null)
                {
                    
    try
                    { 
    return (T)System.Convert.ChangeType(RequestStr, typeof(T)); }
                    
    catch
                    { 
    return defaultValue; }
                }
                
    else
                { 
    return defaultValue; }
            }
            
    #endregion
    泛型函数应用
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text 
    = ConvertRequest<int>("id"0false).ToString();
            Label1.Text 
    = ConvertRequest<string>("catalog""null"true);

        }
  • 相关阅读:
    大数据学习——hive数据类型
    大数据学习——关于hive中的各种join
    大数据学习——hive的sql练习
    大数据学习——hive显示命令
    大数据学习——hive数仓DML和DDL操作
    大数据学习——hive基本操作
    大数据学习——hive使用
    大数据学习——hive安装部署
    大数据学习——日志分析
    大数据学习——mapreduce运营商日志增强
  • 原文地址:https://www.cnblogs.com/jarod99/p/1366612.html
Copyright © 2011-2022 走看看