type是vb里面定義結(jié)構(gòu)的關(guān)鍵字,structure是vb.net中定義的關(guān)鍵字,使用的語言環(huán)境不一樣
我們提供的服務(wù)有:網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、驛城ssl等。為1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的驛城網(wǎng)站制作公司
如果是要判斷引用類型可以用TypeOf來判斷
Dim s = "666"
If TypeOf (s) Is String Then
Debug.Print("string")
Else
Debug.Print("not string")
End If
如果不知道是否是引用類型,可以這樣判斷:
Dim s = 666
If VarType(s) = VariantType.String Then
Debug.Print("string")
Else
Debug.Print("not string")
End If
或者:
Dim s = 666
If s.GetType = "".GetType Then
Debug.Print("string")
Else
Debug.Print("not string")
End If
type 0 即是 type小于或大于0,即type不等于0,C里面的寫法是type!=0
這個功能實現(xiàn)起來其實也很簡單,就是通過反射去讀取 DescriptionAttribute 的 Description 屬性的值,代碼如下所示:
/// summary
/// 返回枚舉項的描述信息。
/// /summary
/// param name="value"要獲取描述信息的枚舉項。/param
/// returns枚舉想的描述信息。/returns
public static string GetDescription(Enum value)
{
Type enumType = value.GetType();
// 獲取枚舉常數(shù)名稱。
string name = Enum.GetName(enumType, value);
if (name != null)
{
// 獲取枚舉字段。
FieldInfo fieldInfo = enumType.GetField(name);
if (fieldInfo != null)
{
// 獲取描述的屬性。
DescriptionAttribute attr = Attribute.GetCustomAttribute(fieldInfo,
typeof(DescriptionAttribute), false) as DescriptionAttribute;
if (attr != null)
{
return attr.Description;
}
}
}
return null;
}
這段代碼還是很容易看懂的,這里取得枚舉常數(shù)的名稱使用的是 Enum.GetName() 而不是 ToString(),因為前者更快,而且對于不是枚舉常數(shù)的值會返回 null,不用進行額外的反射。
當然,這段代碼僅是一個簡單的示例,接下來會進行更詳細的分析。
網(wǎng)站欄目:vb.net中type net和vb
標題網(wǎng)址:http://chinadenli.net/article22/hgdejc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、網(wǎng)站改版、服務(wù)器托管、云服務(wù)器、企業(yè)建站、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)