濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > asp.net 數(shù)據(jù)類型轉(zhuǎn)換類代碼

asp.net 數(shù)據(jù)類型轉(zhuǎn)換類代碼

熱門標(biāo)簽:浙江外呼系統(tǒng)怎么安裝 地圖標(biāo)注多個(gè)行程 上海楊浦怎么申請(qǐng)申請(qǐng)400電話 云南外呼電銷機(jī)器人系統(tǒng) 廈門商鋪地圖標(biāo)注 山西防封卡電銷卡套餐 海外地圖標(biāo)注門市標(biāo) 陜西人工外呼系統(tǒng)哪家好 銅川小型外呼系統(tǒng)運(yùn)營(yíng)商
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace TypeClass
{
public class TypeParse
{
/// summary>
/// 判斷對(duì)象是否為Int32類型的數(shù)字
/// /summary>
/// param name="Expression">/param>
/// returns>/returns>
public static bool IsNumeric(object Expression)
{
if (Expression != null)
{
int intVal;
return int.TryParse(Expression.ToString(), out intVal);
}
return false;
}
public static bool IsDouble(object Expression)
{
if (Expression != null)
{
double doubleVal;
return double.TryParse(Expression.ToString(), out doubleVal);
}
return false;
}
/// summary>
/// string型轉(zhuǎn)換為bool型
/// /summary>
/// param name="strValue">要轉(zhuǎn)換的字符串/param>
/// param name="defValue">缺省值/param>
/// returns>轉(zhuǎn)換后的bool類型結(jié)果/returns>
public static bool StrToBool(object Expression, bool defValue)
{
if (Expression != null)
{
bool boolValue;
if (bool.TryParse(Expression.ToString(), out boolValue))
return boolValue;
else
return defValue;
}
return defValue;
}
/// summary>
/// 將對(duì)象轉(zhuǎn)換為Int32類型
/// /summary>
/// param name="strValue">要轉(zhuǎn)換的字符串/param>
/// param name="defValue">缺省值/param>
/// returns>轉(zhuǎn)換后的Int32類型結(jié)果/returns>
public static int StrToInt(object Expression, int defValue)
{
if (Expression != null)
{
int intValue;
if (int.TryParse(Expression.ToString(), out intValue))
return intValue;
else
return defValue;
}
return defValue;
}
/// summary>
/// string型轉(zhuǎn)換為float型
/// /summary>
/// param name="strValue">要轉(zhuǎn)換的字符串/param>
/// param name="defValue">缺省值/param>
/// returns>轉(zhuǎn)換后的float類型結(jié)果/returns>
public static float StrToFloat(object strValue, float defValue)
{
if (strValue != null)
{
float floatValue;
if (float.TryParse(strValue.ToString(), out floatValue))
return floatValue;
else
return defValue;
}
return defValue;
}
/// summary>
/// string型轉(zhuǎn)換為Decimal型
/// /summary>
/// param name="strValue">要轉(zhuǎn)換的字符串/param>
/// param name="defValue">缺省值/param>
/// returns>轉(zhuǎn)換后的Decimal類型結(jié)果/returns>
public static Decimal StrToDecimal(object strValue, Decimal defValue)
{
if (strValue != null)
{
Decimal decimalValue;
if (Decimal.TryParse(strValue.ToString(), out decimalValue))
return Math.Round(decimalValue,2);
else
return defValue;
}
return defValue;
}
/// summary>
/// string型轉(zhuǎn)換為datetime型
/// /summary>
/// param name="strValue">要轉(zhuǎn)換的字符串/param>
/// param name="defValue">缺省值/param>
/// returns>轉(zhuǎn)換后的datetime類型結(jié)果/returns>
public static DateTime StrToDateTime(object strValue, DateTime defValue)
{
if (strValue != null)
{
DateTime DateTimeValue;
if (DateTime.TryParse(strValue.ToString(), out DateTimeValue))
return DateTimeValue;
else
return defValue;
}
return defValue;
}
/// summary>
/// 判斷給定的字符串?dāng)?shù)組(strNumber)中的數(shù)據(jù)是不是都為數(shù)值型
/// /summary>
/// param name="strNumber">要確認(rèn)的字符串?dāng)?shù)組/param>
/// returns>是則返加true 不是則返回 false/returns>
public static bool IsNumericArray(string[] strNumber)
{
if (strNumber == null)
{
return false;
}
if (strNumber.Length 1)
{
return false;
}
foreach (string id in strNumber)
{
if (!IsNumeric(id))
{
return false;
}
}
return true;
}
}
}

標(biāo)簽:信陽(yáng) 許昌 孝感 常州 自貢 西雙版納 朔州 萊蕪

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net 數(shù)據(jù)類型轉(zhuǎn)換類代碼》,本文關(guān)鍵詞  asp.net,數(shù)據(jù),類型,轉(zhuǎn)換,類,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net 數(shù)據(jù)類型轉(zhuǎn)換類代碼》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于asp.net 數(shù)據(jù)類型轉(zhuǎn)換類代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    张家口市| 商城县| 剑河县| 钟山县| 金乡县| 白朗县| 汾阳市| 密山市| 罗甸县| 浪卡子县| 泗洪县| 龙江县| 民勤县| 黔江区| 仙居县| 陆良县| 绥化市| 安义县| 中卫市| 麻江县| 遵义市| 剑阁县| 恩平市| 读书| 苗栗市| 理塘县| 讷河市| 耿马| 清新县| 石泉县| 康平县| 芜湖县| 浦北县| 灌云县| 新邵县| 淮北市| 象山县| 海南省| 石家庄市| 内黄县| 揭西县|