學習VB.NET這樣一門專門面向對象的編程語言的時候,需要對諸如數據類型等這樣的基礎知識進行重點學習,才能充分掌握這一語言的應用技巧。這些VB.NET基本數據類型也象類一樣擁有各自的方法和屬性,熟練運用它們能讓你的程序更優雅和更有面向對象的味道。
VB.NET基本數據類型的重要方法和屬性舉例
- Dim i As Int32
- Dim s As String
- Dim ss() As String
- Dim by As Byte
- Dim d As Double
- Dim b As Boolean
- Dim da As Date
- Dim c As Char
- Dim cc() As Char
VB.NET基本數據類型之整數操作
- i = Int32.Parse("¥123",
Globalization.NumberStyles.
AllowCurrencySymbol) '123- i = Int32.MaxValue '2147483647
- i = Int32.MinValue '-2147483648
- by = Byte.Parse("1") '1
VB.NET基本數據類型之浮點數操作
- d = Double.Positive
Infinity '正無窮大- d = Double.Epsilon
'4.94065645841247E-324
VB.NET基本數據類型之布爾操作
- s = Boolean.TrueString 'True
VB.NET基本數據類型之日期操作
- da = Date.MaxValue
- '9999-12-31 23:59:59
- da = Date.MinValue
- '0:00:00
- da = Date.Now
- '2004-5-7 13:17:35
- b = Date.IsLeapYear(2004)
- 'True
- i = Date.DaysInMonth(2004, 5)
- '31
以下方法用於判斷字符的特性
- Char.IsControl(c)
- Char.IsDigit(c)
- Char.IsLetter(c)
- Char.IsLetterOrDigit(c)
- Char.IsLower(c)
- Char.IsNumber(c)
- Char.IsPunctuation(c)
- Char.IsSeparator(c)
- Char.IsSurrogate(c)
- Char.IsSymbol(c)
- Char.IsWhiteSpace(c)
- Char.IsUpper(c)
Char轉換
- Char.ToLower(c)
- Char.ToUpper(c)
VB.NET基本數據類型之字符串操作
- cc = s.ToCharArray()
- sss = s.Split(",")
- ss = s.Substring(5, 3)
- ss = s.Trim()