打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VB.NET教程

VB.Net - 字符串

在VB.Net中,可以使用字符串作为字符数组,但是更常见的做法是使用String关键字声明一个字符串变量。 string关键字是System.String类的别名。

创建一个字符串对象

您可以使用以下方法之一创建字符串对象:

By assigning a string literal to a String variable 通过指定一个字符串给一个字符串变量 

By using a String class constructor 通过使用String类构造函数

By using the string concatenation operator (+) 通过使用字符串连接运算符(+) 

By retrieving a property or calling a method that returns a string 通过检索属性或调用返回字符串的方法

By calling a formatting method to convert a value or object to its string representation

通过调用格式化方法将值或对象转换为其字符串表示形式

下面的例子说明了这一点:

Module strings

Sub Main()

Dim fname, lname, fullname, greetings As String

fname = 'Rowan'

lname = 'Atkinson'

fullname = fname + ' ' + lname

Console.WriteLine('Full Name: {0}', fullname)

'by using string constructor

Dim letters As Char() = {'H', 'e', 'l', 'l', 'o'}

greetings = New String(letters)

Console.WriteLine('Greetings: {0}', greetings)

'methods returning String

Dim sarray() As String = {'Hello', 'From', 'Tutorials', 'Point'}

Dim message As String = String.Join(' ', sarray)

Console.WriteLine('Message: {0}', message)

'formatting method to convert a value

Dim waiting As DateTime = New DateTime(2012, 12, 12, 17, 58, 1)

Dim chat As String = String.Format('Message sent at {0:t} on {0:D}', waiting)

Console.WriteLine('Message: {0}', chat)

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Full Name: Rowan AtkinsonGreetings: HelloMessage: Hello From Tutorials PointMessage: Message sent at 5:58 PM on Wednesday, December 12, 2012

String类的属性

String类有以下两个属性:

SN 属性名称和说明

1

Chars

获取当前String对象中指定位置的Char对象。

2

Length

获取当前String对象中的字符数。

String类的方法

String类有许多方法可以帮助你处理字符串对象。 下表提供了一些最常用的方法:

SN 方法名称和说明

1

Public Shared Function Compare ( strA As String, strB As String ) As Integer

公共共享函数比较(strA As String,strB As String)As Integer

比较两个指定的字符串对象,并返回一个整数,指示它们在排序顺序中的相对位置。

2

Public Shared Function Compare ( strA As String, strB As String, ignoreCase As Boolean ) As Integer

公共共享函数比较(strA As String,strB As String,ignoreCase As Boolean)As Integer

比较两个指定的字符串对象,并返回一个整数,指示它们在排序顺序中的相对位置。 但是,如果布尔参数为true,它将忽略大小写。

3

Public Shared Function Concat ( str0 As String, str1 As String ) As String

公共共享函数Concat(str0 As String,str1 As String)As String

连接两个字符串对象。

4

Public Shared Function Concat ( str0 As String, str1 As String, str2 As String ) As String

公共共享函数Concat(str0 As String,str1 As String,str2 As String)As String

连接三个字符串对象。

5

Public Shared Function Concat ( str0 As String, str1 As String, str2 As String, str3 As String ) As String公共共享函数Concat(str0 As String,str1 As String,str2 As String,str3 As String)As String

连接四个字符串对象。

6

Public Function Contains ( value As String ) As Boolean

公共函数包含(值作为字符串)As Boolean

返回一个值,指示指定的字符串对象是否出现在此字符串中。

7

Public Shared Function Copy ( str As String ) As String

公共共享函数复制(str作为字符串)As String

创建与指定字符串具有相同值的新String对象。

8

pPublic Sub CopyTo ( sourceIndex As Integer, destination As Char(), destinationIndex As Integer, count As Integer )

将指定数量的字符从字符串对象的指定位置复制到Unicode字符数组中的指定位置。

9

Public Function EndsWith ( value As String ) As Boolean

公共函数endsWith(值作为字符串)As Boolean

确定字符串对象的结尾是否与指定的字符串匹配。

10

Public Function Equals ( value As String ) As Boolean

公共函数等于(值作为字符串)As Boolean

确定当前字符串对象,并指定字符串对象是否具有相同的值。

11

Public Shared Function Equals ( a As String, b As String ) As Boolean

公共共享函数等于(A作为字符串,B作为字符串)As Boolean

确定两个指定字符串对象是否具有相同的值。

12

Public Shared Function Format ( format As String, arg0 As Object ) As String

公共共享函数格式(格式作为字符串,arg0作为对象)As String

将指定字符串中的一个或多个格式项替换为指定对象的字符串表示形式。

13

Public Function IndexOf ( value As Char ) As Integer

公共函数IndexOf(价值为CHAR)As Integer

返回当前字符串中指定Unicode字符第一次出现的从零开始的索引。

14

Public Function IndexOf ( value As String ) As Integer

公共函数IndexOf(值作为字符串)As Integer

返回此实例中指定字符串第一次出现的从零开始的索引。

15

Public Function IndexOf ( value As Char, startIndex As Integer ) As Integer

公共函数IndexOf(值为char,则startIndex作为整数) As Integer

返回此字符串中指定Unicode字符第一次出现的从零开始的索引,从指定的字符位置开始搜索。

16

Public Function IndexOf ( value As String, startIndex As Integer ) As Integer

公共函数IndexOf(值作为字符串,则startIndex作为整数)As Integer

返回此实例中指定字符串第一次出现的从零开始的索引,开始在指定的字符位置搜索。

17

Public Function IndexOfAny ( anyOf As Char() ) As Integer

公共函数IndexOfAny(anyOf为CHAR())As Integer

返回在指定的Unicode字符数组中的任何字符的此实例中第一次出现的从零开始的索引。

18

Public Function IndexOfAny ( anyOf As Char(), startIndex As Integer ) As Integer

公共函数IndexOfAny(anyOf为char(),则startIndex作为整数)As Integer

返回在指定的Unicode字符数组中的任意字符的此实例中第一次出现的从零开始的索引,开始在指定的字符位置搜索。

19

Public Function Insert ( startIndex As Integer, value As String ) As String

公共函数Insert(的startIndex为整数,值作为字符串)As String

返回一个新字符串,其中指定的字符串插入到当前字符串对象中指定的索引位置。

20

Public Shared Function IsNullOrEmpty ( value As String ) As Boolean

公共共享函数IsNullOrEmpty(值作为字符串) As Boolean

指示指定的字符串是空还是空字符串。

21

Public Shared Function Join ( separator As String, ParamArray value As String() ) As String

公共共享函数加入(分隔符作为字符串,值的ParamArray作为字符串())As String

连接字符串数组的所有元素,使用每个元素之间指定的分隔符。

22

Public Shared Function Join ( separator As String, value As String(), startIndex As Integer, count As Integer ) As String

公共共享函数加入(分隔符作为字符串,值作为字符串(),则startIndex整数,算作整数)As String

使用每个元素之间指定的分隔符连接字符串数组的指定元素。

23

Public Function LastIndexOf ( value As Char ) As Integer

公共函数LastIndexOf(价值为CHAR) As Integer

返回当前字符串对象中指定Unicode字符的最后一次出现的从零开始的索引位置。

24

Public Function LastIndexOf ( value As String ) As Integer

公共函数LastIndexOf(值作为字符串) As Integer

返回当前字符串对象中指定字符串的最后一次出现的从零开始的索引位置。

25

Public Function Remove ( startIndex As Integer )As String

字符串作为公共函数删除 (startIndex 作为整数)As String

删除当前实例中的所有字符,从指定位置开始,并继续到最后一个位置,并返回字符串。

26

Public Function Remove ( startIndex As Integer, count As Integer ) As String

字符串作为公共函数删除 (startIndex 作为整数作为整数计数)As String

从指定位置开始删除当前字符串中指定数量的字符,并返回字符串。

27

Public Function Replace ( oldChar As Char, newChar As Char ) As String

公共函数替换(oldChar为char,newChar为CHAR)As String

用指定的Unicode字符替换当前字符串对象中指定Unicode字符的所有出现,并返回新字符串。

28

Public Function Replace ( oldValue As String, newValue As String ) As String

公共功能替换(属性oldValue作为字符串,newValue作为字符串)As String

将当前字符串对象中指定字符串的所有出现替换为指定的字符串,并返回新字符串。

29

Public Function Split ( ParamArray separator As Char() ) As String()

公共函数拆分(ParamArray分隔符作为Char())As String()

返回一个字符串数组,其中包含当前字符串对象中的子字符串,由指定的Unicode字符数组的元素分隔。

30

Public Function Split ( separator As Char(), count As Integer ) As String()

公共函数分割(分隔符为char(),计数为整数)As String()

返回一个字符串数组,其中包含当前字符串对象中的子字符串,由指定的Unicode字符数组的元素分隔。 int参数指定要返回的子字符串的最大数目。

31

Public Function StartsWith ( value As String ) As Boolean

公共函数StartsWith(值作为字符串)As Boolean

确定此字符串实例的开头是否与指定的字符串匹配。

32

Public Function ToCharArray As Char()

公共函数ToCharArray As CHAR()

返回包含当前字符串对象中所有字符的Unicode字符数组。

33

Public Function ToCharArray ( startIndex As Integer, length As Integer ) As Char()

公共函数ToCharArray(startIndex为整数,length为整数) As Char()

返回一个Unicode字符数组,其中包含当前字符串对象中的所有字符,从指定的索引开始,直到指定的长度。

34

Public Function ToLower As String

公共函数ToLower As String

返回此字符串的转换为小写的副本。

35

Public Function ToUpper As String

公共函数ToUpper As String

返回此字符串的转换为大写的副本。

36

Public Function Trim As String

公共函数Trim As String

从当前String对象中删除所有前导和尾部空格字符。

上面列出的方法并不详尽,请访问MSDN库获取完整的方法列表和String类构造函数。

例子:

下面的例子说明了上述一些方法:

比较字符串:

Module strings

Sub Main()

Dim str1, str2 As String

str1 = 'This is test'

str2 = 'This is text'

If (String.Compare(str1, str2) = 0) Then

Console.WriteLine(str1 + ' and ' + str2 +

' are equal.')

Else

Console.WriteLine(str1 + ' and ' + str2 +

' are not equal.')

End If

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:This is test and This is text are not equal.

字符串包含字符串:

Module strings

Sub Main()

Dim str1 As String

str1 = 'This is test'

If (str1.Contains('test')) Then

Console.WriteLine('The sequence 'test' was found.')

End If

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:The sequence 'test' was found.

获取的子字符串:

Module strings

Sub Main()

Dim str As String

str = 'Last night I dreamt of San Pedro'

Console.WriteLine(str)

Dim substr As String = str.Substring(23)

Console.WriteLine(substr)

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Last night I dreamt of San PedroSan Pedro.

加入字符串:

Module strings

Sub Main()

Dim strarray As String() = {'Down the way where the nights are gay',

'And the sun shines daily on the mountain top',

'I took a trip on a sailing ship',

'And when I reached Jamaica',

'I made a stop'}

Dim str As String = String.Join(vbCrLf, strarray)

Console.WriteLine(str)

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Down the way where the nights are gayAnd the sun shines daily on the mountain topI took a trip on a sailing shipAnd when I reached JamaicaI made a stop

VB.Net - 日期和时间

你写的大部分软件都需要实现某种形式的日期功能,返回当前日期和时间。日期是日常生活的一部分,使用它能让工作变得轻松,不需要太多思考。 VB.Net还提供了强大的日期算术工具,使操作日期变得容易。

日期数据类型包含日期值,时间值或日期和时间值。 Date的默认值为0001年1月1日的0:00:00(午夜)。等效的.NET数据类型为System.DateTime。

DateTime 结构表示即时时间,通常表示为日期和时间的一天

'Declaration

_

Public Structure DateTime _

Implements IComparable, IFormattable, IConvertible, ISerializable,

IComparable(Of DateTime), IEquatable(Of DateTime)

您还可以从DateAndTime类获取当前日期和时间。

DateAndTime模块包含日期和时间操作中使用的过程和属性。'Declaration _Public NotInheritable Class DateAndTime

注意:

DateTime结构和DateAndTime模块都包含诸如Now和Today之类的属性,因此初学者经常会感到困惑。 DateAndTime类属于Microsoft.VisualBasic命名空间,DateTime结构属于System命名空间。

因此,使用以后的将帮助你移植你的代码到另一个.Net语言,如C#。 但是,DateAndTime类/模块包含Visual Basic中所有可用的旧日期函数。

DateTime结构的属性和方法

下表列出了一些DateTime结构的常用属性 :

S.N 属性 描述

1

Date

Gets the date component of this instance.

获取此实例的日期组件。

2

Day

Gets the day of the month represented by this instance.

获取此实例所代表的月份中的某一天。

3

DayOfWeek

Gets the day of the week represented by this instance.

获取此实例表示的星期几。

4

DayOfYear

Gets the day of the year represented by this instance.

获取此实例表示的一年中的某一天。

5

Hour

Gets the hour component of the date represented by this instance.

获取此实例表示的日期的小时组件。

6

Kind

Gets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither.G

获取一个值,该值指示此实例表示的时间是基于本地时间,协调世界时间(UTC)还是两者都不是。

7

Millisecond

Gets the milliseconds component of the date represented by this instance.

获取此实例表示的日期的毫秒组件。

8

Minute

Gets the minute component of the date represented by this instance.

获取此实例表示的日期的分钟分量。

9

Month

Gets the month component of the date represented by this instance.

获取此实例表示的日期的月份。

10

Now

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

获取在此计算机上设置为当前日期和时间的DateTime对象,以本地时间表示。

11

Second

Gets the seconds component of the date represented by this instance.

获取此实例表示的日期的秒组件。

12

Ticks

Gets the number of ticks that represent the date and time of this instance.

获取表示此实例的日期和时间的刻度数。

13

TimeOfDay

Gets the time of day for this instance.

获取此实例的时间。

14

Today

Gets the current date.

获取当前日期。

15

UtcNow

Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

获取设置为此计算机上当前日期和时间的DateTime对象,以协调世界时(UTC)表示。

16

Year

Gets the year component of the date represented by this instance.

获取此实例表示的日期的年份组件。

下表列出了DateTime结构的一些常用方法:

SN 方法名称和说明

1

Public Function Add (value As TimeSpan) As DateTime

公共函数Add(值作为时间跨度)As DateTime

返回一个新的DateTime,将指定的TimeSpan的值添加到此实例的值。

2

Public Function AddDays ( value As Double) As DateTime

公共函数AddDays(值为双)As DateTime

返回一个新的DateTime,该值将指定的天数添加到此实例的值中。

3

Public Function AddHours (value As Double) As DateTime

公共函数AddHours(值为双)As DateTime

返回一个新的DateTime,该值将指定的小时数添加到此实例的值中。

4

Public Function AddMinutes (value As Double) As DateTime

公共函数AddMinutes(值为双)As DateTime

返回一个新的DateTime,将指定的分钟数添加到此实例的值。

5

Public Function AddMonths (months As Integer) As DateTime

公共函数AddMonths(月作为整数)As DateTime

返回一个新的DateTime,将指定的月数添加到此实例的值。

6

Public Function AddSeconds (value As Double) As DateTime

公共函数AddSeconds(值为双)As DateTime

返回一个新的DateTime,将指定的秒数添加到此实例的值。

7

Public Function AddYears (value As Integer ) As DateTime

公共函数AddYears(值为整数) As DateTime

返回一个新的DateTime,将指定的年数添加到此实例的值。

8

Public Shared Function Compare (t1 As DateTime,t2 As DateTime) As Integer

公共共享函数比较(T1作为日期时间,T2为DATETIME)As Integer

比较两个DateTime实例,并返回一个整数,指示第一个实例是早于,与第二个实例相同还是晚于第二个实例。

9

Public Function CompareTo (value As DateTime) As Integer

公共函数CompareTo(值为DATETIME)As Integer

将此实例的值与指定的DateTime值进行比较,并返回一个整数,指示此实例是早于,等于还是晚于指定的DateTime值。

10

Public Function Equals (value As DateTime) As Boolean

公共函数等于(值为DATETIME)As Boolean

返回一个值,表示此实例的值是否等于指定的DateTime实例的值。

11

Public Shared Function Equals (t1 As DateTime, t2 As DateTime) As Boolean

公共共享函数等于(T1作为日期时间,T2为DATETIME) As Boolean

返回一个值,指示两个DateTime实例是否具有相同的日期和时间值。

12

Public Overrides Function ToString As String

公共覆盖函数ToString  As String

将当前DateTime对象的值转换为其等效字符串表示形式。

以上列出的方法并不详尽,请访问微软的文档以获取DateTime结构的方法和属性的完整列表。

创建DateTime对象

您可以通过以下方式之一创建DateTime对象:

By calling a DateTime constructor from any of the overloaded DateTime constructors.通过从任何重载的DateTime构造函数调用DateTime构造函数。

By assigning the DateTime object a date and time value returned by a property or method.

通过为DateTime对象分配属性或方法返回的日期和时间值。

By parsing the string representation of a date and time value.

通过解析日期和时间值的字符串表示。

By calling the DateTime structure's implicit default constructor.

通过调用DateTime结构的隐式默认构造函数。

下面的例子说明了这一点:

Module Module1

Sub Main()

'DateTime constructor: parameters year, month, day, hour, min, sec

Dim date1 As New Date(2012, 12, 16, 12, 0, 0)

'initializes a new DateTime value

Dim date2 As Date = #12/16/2012 12:00:52 AM#

'using properties

Dim date3 As Date = Date.Now

Dim date4 As Date = Date.UtcNow

Dim date5 As Date = Date.Today

Console.WriteLine(date1)

Console.WriteLine(date2)

Console.WriteLine(date3)

Console.WriteLine(date4)

Console.WriteLine(date5)

Console.ReadKey()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:12/16/2012 12:00:00 PM12/16/2012 12:00:52 PM12/12/2012 10:22:50 PM12/12/2012 12:00:00 PM

获取当前日期和时间:

以下程序演示如何获取VB.Net中的当前日期和时间:

当前时间:

Module dateNtime

Sub Main()

Console.Write('Current Time: ')

Console.WriteLine(Now.ToLongTimeString)

Console.ReadKey()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Current Time: 11 :05 :32 AM

当前日期:

Module dateNtime

Sub Main()

Console.WriteLine('Current Date: ')

Dim dt As Date = Today

Console.WriteLine('Today is: {0}', dt)

Console.ReadKey()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Today is: 12/11/2012 12:00:00 AM

格式化日期

日期字面值应该用哈希符号(##)括起来,并以M / d / yyyy格式指定,例如#12/16/2012#。 否则,您的代码可能会更改,具体取决于运行应用程序的语言环境。

例如,您为2012年2月6日的日期指定了#2/6/2012#的日期字面值。对于使用mm / dd / yyyy格式的语言环境,这是正确的。 但是,在使用dd / mm / yyyy格式的语言环境中,您的文本将编译为2012年6月2日。如果语言环境使用另一种格式,例如yyyy / mm / dd,该文字将无效并导致编译器错误。

要将Date字面值转换为语言环境的格式或自定义格式,请使用String类的Format函数,指定预定义或用户定义的日期格式。

下面的例子演示了这一点。

Module dateNtime

Sub Main()

Console.WriteLine('India Wins Freedom: ')

Dim independenceDay As New Date(1947, 8, 15, 0, 0, 0)

' Use format specifiers to control the date display.

Console.WriteLine(' Format 'd:' ' & independenceDay.ToString('d'))

Console.WriteLine(' Format 'D:' ' & independenceDay.ToString('D'))

Console.WriteLine(' Format 't:' ' & independenceDay.ToString('t'))

Console.WriteLine(' Format 'T:' ' & independenceDay.ToString('T'))

Console.WriteLine(' Format 'f:' ' & independenceDay.ToString('f'))

Console.WriteLine(' Format 'F:' ' & independenceDay.ToString('F'))

Console.WriteLine(' Format 'g:' ' & independenceDay.ToString('g'))

Console.WriteLine(' Format 'G:' ' & independenceDay.ToString('G'))

Console.WriteLine(' Format 'M:' ' & independenceDay.ToString('M'))

Console.WriteLine(' Format 'R:' ' & independenceDay.ToString('R'))

Console.WriteLine(' Format 'y:' ' & independenceDay.ToString('y'))

Console.ReadKey()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:India Wins Freedom:Format 'd:' 8/15/1947Format 'D:' Friday, August 15, 1947Format 't:' 12:00 AMFormat 'T:' 12:00:00 AMFormat 'f:' Friday, August 15, 1947 12:00 AMFormat 'F:' Friday, August 15, 1947 12:00:00 AMFormat 'g:' 8/15/1947 12:00 AMFormat 'G:' 8/15/1947 12:00:00 AMFormat 'M:' 8/15/1947 August 15Format 'R:' Fri, 15 August 1947 00:00:00 GMTFormat 'y:' August, 1947

预定义的日期/时间格式

下表列出了预定义的日期和时间格式名称。 可以通过这些名称用作Format函数的样式参数:

格式 描述

General Date, or G

Displays a date and/or time. For example, 1/12/2012 07:07:30 AM

显示日期和/或时间。 例如,1/12/2012 07:07:30 AM。.

Long Date,Medium Date, or D

Displays a date according to your current culture's long date format. For example, Sunday, December 16,2012.

根据您当前区域的长日期格式显示日期。 例如,2012年12月16日星期日

Short Date, or d

Displays a date using your current culture's short date format. For example, 12/12/2012

使用当前区域短日期格式显示日期。 例如,12/12/2012。.

Long Time,Medium Time, orT

Displays a time using your current culture's long time format; typically includes hours, minutes, seconds. For example, 01:07:30 AM

使用您当前区域的长时间格式显示时间; 通常包括小时,分钟,秒。 例如,01:07:30 AM。.

Short Time or t

Displays a time using your current culture's short time format. For example, 11:07 AM

使用当前区域的短时格式显示时间。 例如,11:07 AM。.

f

Displays the long date and short time according to your current culture's format. For example, Sunday, December 16, 2012 12:15 AM

根据您当前的区域格式显示长日期和短时间。 例如,2012年12月16日星期日上午12:15。.

F

Displays the long date and long time according to your current culture's format. For example, Sunday, December 16, 2012 12:15:31 AM

根据您当前的区域格式显示长日期和长时间。 例如,2012年12月16日星期日12:15:31 AM。.

g

Displays the short date and short time according to your current culture's format. For example, 12/16/2012 12:15 AM

根据您当前的区域格式显示短日期和短时间。 例如,12/16/2012 12:15 AM。.

M, m

Displays the month and the day of a date. For example, December 16

显示日期的月份和日期。 例如,12月16日。.

R, r

Formats the date according to the RFC1123Pattern property

根据RFC1123Pattern属性格式化日期。.

s

Formats the date and time as a sortable index. For example, 2012-12-16T12:07:31

将日期和时间格式化为可排序索引。 例如,2012-12-16T12:07:31。.

u

Formats the date and time as a GMT sortable index. For example, 2012-12-16 12:15:31Z

将日期和时间格式设置为GMT可排序索引。 例如,2012-12-16 12:15:31Z。.

U

Formats the date and time with the long date and long time as GMT. For example, Sunday, December 16, 2012 6:07:31 PM

将日期和时间格式设置为长日期和长时间,格式为GMT。 例如,星期日,2012年12月16日下午6:07:31。.

Y, y

Formats the date as the year and month. For example, December, 2012

将日期格式设置为年和月。 例如,2012年12月。.

对于其他格式,如用户定义的格式,请参阅Microsoft文档 。

属性和DateAndTime类的方法

下表列出了一些DateAndTime类的常用属性 :

SN 属性 描述

1

Date

Returns or sets a String value representing the current date according to your system.

返回或设置根据系统代表当前日期的字符串值。

2

Now

Returns a Date value containing the current date and time according to your system.

返回一个包含根据系统的当前日期和时间的日期值。

3

TimeOfDay

Returns or sets a Date value containing the current time of day according to your system.

返回或设置根据你的系统包含当天的当前时间的日期值。

4

Timer

Returns a Double value representing the number of seconds elapsed since midnight.

返回表示自午夜起经过的秒数为Double值。

5

TimeString

Returns or sets a String value representing the current time of day according to your system.

返回或设置根据你的系统代表一天的当前时间的字符串值。

6

Today

Gets the current date.

获取当前日期。

下表列出了一些DateAndTime类的常用方法 :

SN 方法名称和说明

1

Public Shared Function DateAdd (Interval As DateInterval, Number As Double, DateValue As DateTime) As DateTime

公共共享函数使用DateAdd(时间间隔为DateInterval,号码为DOUBLE,则DateValue为DATETIME)为DATETIME

返回包含已添加指定时间间隔的日期和时间值的Date值。

2

Public Shared Function DateAdd (Interval As String,Number As Double,DateValue As Object ) As DateTime

公共共享函数使用DateAdd(时间间隔为字符串,数字为DOUBLE,则DateValue作为对象)为DATETIME

返回包含已添加指定时间间隔的日期和时间值的Date值。

3

Public Shared Function DateDiff (Interval As DateInterval, Date1 As DateTime, Date2 As DateTime, DayOfWeek As FirstDayOfWeek, WeekOfYear As FirstWeekOfYear ) As Long

公共共享函数DateDiff(时间间隔为DateInterval,日期1为DATETIME,日期2为DATETIME,星期作为Firstdayofweek,WEEKOFYEAR作为FirstWeekOfYear)As Long

返回指定两个日期值之间的时间间隔数的长整型值。

4

Public Shared Function DatePart (Interval As DateInterval, DateValue As DateTime, FirstDayOfWeekValue As FirstDayOfWeek, FirstWeekOfYearValue As FirstWeekOfYear ) As Integer

公共共享函数DATEPART(时间间隔为DateInterval,则DateValue为DATETIME,FirstDayOfWeekValue作为Firstdayofweek可,FirstWeekOfYearValue作为FirstWeekOfYear)作为整数

返回包含给定Date值的指定组件的整数值。

5

Public Shared Function Day (DateValue As DateTime) As Integer

公共共享函数Day(DateValue将作为DATETIME)作为整数

返回从1到31的整数值,表示每月的某一天。

6

Public Shared Function Hour (TimeValue As DateTime) As Integer

公共共享函数Hour (TIMEVALUE为DATETIME)作为整数

返回从0到23的整数值,表示一天中的小时。

7

Public Shared Function Minute (TimeValue As DateTime) As Integer

公共共享函数Minute(TIMEVALUE为DATETIME)作为整数

返回一个从0到59的整数值,表示小时的分钟。

8

Public Shared Function Month (DateValue As DateTime) As Integer

公共共享函数Month(DateValue将作为DATETIME)作为整数

返回从1到12的整数值,表示一年中的月份。

9

Public Shared Function MonthName (Month As Integer, Abbreviate As Boolean) As String

公共共享函数MONTHNAME(月为整数,简称布尔)作为字符串

返回包含指定月份的名称的字符串值。

10

Public Shared Function Second (TimeValue As DateTime) As Integer

公共共享函数Second(TIMEVALUE为DATETIME)作为整数

返回从0到59,代表分钟的第二个整数值。

11

Public Overridable Function ToString As String

公众可重写的ToString函数作为字符串

返回表示当前对象的字符串。

12

Public Shared Function Weekday (DateValue As DateTime, DayOfWeek As FirstDayOfWeek) As Integer

公共共享函数Weekday (DateValue将作为日期时间,星期由于Firstdayofweek可)作为整数

返回包含表示星期几的一个数的整数值。

13

Public Shared Function WeekdayName (Weekday As Integer, Abbreviate As Boolean, FirstDayOfWeekValue As FirstDayOfWeek) As String

公共共享函数WEEKDAYNAME(平日为整数,简称布尔,FirstDayOfWeekValue作为Firstdayofweek可)作为字符串

返回包含指定工作日名称的字符串值。

14

Public Shared Function Year (DateValue As DateTime) As Integer

公共共享函数(一年则DateValue为DATETIME)作为整数

返回从1到9999表示年份的整数值。

上述名单并不详尽。有关属性和DateAndTime类的方法的完整列表,请参阅微软的文档。

下面的程序演示其中的一些方法:

Module Module1

Sub Main()

Dim birthday As Date

Dim bday As Integer

Dim month As Integer

Dim monthname As String

' Assign a date using standard short format.

birthday = #7/27/1998#

bday = Microsoft.VisualBasic.DateAndTime.Day(birthday)

month = Microsoft.VisualBasic.DateAndTime.Month(birthday)

monthname = Microsoft.VisualBasic.DateAndTime.MonthName(month)

Console.WriteLine(birthday)

Console.WriteLine(bday)

Console.WriteLine(month)

Console.WriteLine(monthname)

Console.ReadKey()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:7/27/1998 12:00:00 AM277July

VB.Net - 数组

数组存储相同类型的元素的固定大小顺序集合。 数组用于存储数据集合,但将数组视为同一类型的变量的集合通常更有用。

所有数组由连续的内存位置组成。 最低地址对应于第一个元素,最高地址对应于最后一个元素。

在VB.Net中创建数组

要在VB.Net中声明数组,可以使用Dim语句。 例如,

Dim intData(30) ' an array of 31 elements

Dim strData(20) As String ' an array of 21 strings

Dim twoDarray(10, 20) As Integer 'a two dimensional array of integers

Dim ranges(10, 100) 'a two dimensional array

您还可以在声明数组时初始化数组元素。 例如,Dim intData() As Integer = {12, 16, 20, 24, 28, 32}Dim names() As String = {'Karthik', 'Sandhya', _'Shivangi', 'Ashwitha', 'Somnath'}Dim miscData() As Object = {'Hello World', 12d, 16ui, 'A'c}

可以通过使用数组的索引来存储和访问数组中的元素。 以下程序演示了这一点:

Module arrayApl

Sub Main()

Dim n(10) As Integer ' n is an array of 11 integers '

Dim i, j As Integer

' initialize elements of array n '

For i = 0 To 10

n(i) = i + 100 ' set element at location i to i + 100

Next i

' output each array element's value '

For j = 0 To 10

Console.WriteLine('Element({0}) = {1}', j, n(j))

Next j

Console.ReadKey()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Element(0) = 100Element(1) = 101Element(2) = 102Element(3) = 103Element(4) = 104Element(5) = 105Element(6) = 106Element(7) = 107Element(8) = 108Element(9) = 109Element(10) = 110

动态数组

动态数组是可以根据程序需要进行维度和重新定义的数组。 您可以使用ReDim语句声明一个动态数组。

ReDim语句的语法:

ReDim [Preserve] arrayname(subscripts)

Preserve关键字有助于在调整现有数组大小时保留现有数组中的数据。

arrayname是要重新维度的数组的名称。

subscripts指定新维度。

Module arrayAplSub Main()Dim marks() As IntegerReDim marks(2)marks(0) = 85marks(1) = 75marks(2) = 90ReDim Preserve marks(10)marks(3) = 80marks(4) = 76marks(5) = 92marks(6) = 99marks(7) = 79marks(8) = 75For i = 0 To 10Console.WriteLine(i & vbTab & marks(i))Next iConsole.ReadKey()End SubEnd Module

当上述代码被编译和执行时,它产生了以下结果:

0 85

1 75

2 90

3 80

4 76

5 92

6 99

7 79

8 75

9 0

10 0

多维数组

VB.Net允许多维数组。多维数组也被称为矩形数组。

你可以声明一个二维的字符串数组:Dim twoDStringArray(10, 20) As String

或者,整数变量的3维数组:

Dim threeDIntArray(10, 10, 10) As Integer

下面的程序演示创建和使用二维数组:Module arrayAplSub Main()' an array with 5 rows and 2 columnsDim a(,) As Integer = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 8}}Dim i, j As Integer' output each array element's value 'For i = 0 To 4For j = 0 To 1Console.WriteLine('a[{0},{1}] = {2}', i, j, a(i, j))Next jNext iConsole.ReadKey()End SubEnd Module

当上述代码被编译和执行时,它产生了以下结果:

a[0,0]: 0

a[0,1]: 0

a[1,0]: 1

a[1,1]: 2

a[2,0]: 2

a[2,1]: 4

a[3,0]: 3

a[3,1]: 6

a[4,0]: 4

a[4,1]: 8

不规则数组

Jagged数组是一个数组的数组。 以下代码显示了声明一个名为score of Integers的不规则数组:Dim scores As Integer()() = New Integer(5)(){}

下面的例子说明使用不规则数组:

Module arrayApl

Sub Main()

'a jagged array of 5 array of integers

Dim a As Integer()() = New Integer(4)() {}

a(0) = New Integer() {0, 0}

a(1) = New Integer() {1, 2}

a(2) = New Integer() {2, 4}

a(3) = New Integer() {3, 6}

a(4) = New Integer() {4, 8}

Dim i, j As Integer

' output each array element's value

For i = 0 To 4

For j = 0 To 1

Console.WriteLine('a[{0},{1}] = {2}', i, j, a(i)(j))

Next j

Next i

Console.ReadKey()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:a[0][0]: 0a[0][1]: 0a[1][0]: 1a[1][1]: 2a[2][0]: 2a[2][1]: 4a[3][0]: 3a[3][1]: 6a[4][0]: 4a[4][1]: 8

Array类

Array类是VB.Net中所有数组的基类。 它在系统命名空间中定义。 Array类提供了处理数组的各种属性和方法。

Array类的属性

下表提供了一些Array类中最常用的属性 :

SN 属性名称和说明

1

IsFixedSize

Gets a value indicating whether the Array has a fixed size.

获取一个值,指示数组是否具有固定大小。

2

IsReadOnly

Gets a value indicating whether the Array is read-only.

获取一个值,该值指示Array是否为只读。

3

Length

Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.

获取一个32位整数,表示数组所有维度中元素的总数。

4

LongLength

Gets a 64-bit integer that represents the total number of elements in all the dimensions of the Array.

获取一个64位整数,表示数组所有维度中元素的总数。

5

Rank

Gets the rank (number of dimensions) of the Array.

获取数组的排名(维数)。

Array类的方法

下表提供了一些最常用的Array类方法:

SN 方法名称和说明

1

Public Shared Sub Clear (array As Array, index As Integer, length As Integer)

公共共享子清除(数组为数组,指数为整数,长度为整数)

设置一个范围的数组元素的零,为false,或为空,这取决于元素类型。

2

Public Shared Sub Copy (sourceArray As Array, destinationArray As Array, length As Integer)

公共共享子复制(sourceArray作为数组,destinationArray作为数组,长度为整数)

复制一定范围内由数组以第一个元素的元素,并将它们粘贴到起始于第一个元素另一个数组。长度被指定为32位整数。

3

Public Sub CopyTo (array As Array, index As Integer)

公共Sub CopyTo(数组为数组,指数为整数)

将当前的一维数组到指定的一维数组从指定的目标数组索引处的所有元素。索引被指定为32位整数。

4

Public Function GetLength (dimension As Integer) As Integer

公共功能对GetLength(尺寸为整数)作为整数

获取一个32位整数,它表示数组的指定维中的元素的数量。

5

Public Function GetLongLength (dimension As Integer) As Long

公共职能GetLongLength(尺寸为整数),只要

获取一个64位整数,它代表了数组的指定维中的元素的数量。

6

Public Function GetLowerBound (dimension As Integer) As Integer

公共职能GetLowerBound(尺寸为整数)作为整数

获取下界在数组中指定的尺寸。

7

Public Function GetType As Type

公共职能的GetType为类型

获取当前实例的类型(从Object继承)。

8

Public Function GetUpperBound (dimension As Integer) As Integer

公共职能GetUpperBound(尺寸为整数)作为整数

获取上限在数组中指定的尺寸。

9

Public Function GetValue (index As Integer) As Object

公共职能的GetValue(指数为整数)作为对象

获取在一维数组中指定位置的值。索引被指定为32位整数。

10

Public Shared Function IndexOf (array As Array,value As Object) As Integer

公共共享功能的IndexOf(数组作为数组,值作为对象)作为整数

搜索指定的对象,并返回第一次出现的整个一维数组中的索引。

11

Public Shared Sub Reverse (array As Array)

公共共享子反向(阵列阵列)

反转在整个一维数组中的元素的顺序。

12

Public Sub SetValue (value As Object, index As Integer)

公用Sub的SetValue(价值为对象,指数为整数)

在一维阵列中的指定位置设置一个值的元素。索引被指定为32位整数。

13

Public Shared Sub Sort (array As Array)

公共共享子排序(数组为数组)

使用排序了IComparable实现阵列中的每个元素在整个一维数组中的元素。

14

Public Overridable Function ToString As String

公众可重写的ToString函数作为字符串

返回表示当前对象(从Object继承)的字符串。

有关Array类属性和方法的完整列表,请参阅Microsoft文档。

示例

下面的程序演示使用的一些Array类的方法:

Module arrayApl

Sub Main()

Dim list As Integer() = {34, 72, 13, 44, 25, 30, 10}

Dim temp As Integer() = list

Dim i As Integer

Console.Write('Original Array: ')

For Each i In list

Console.Write('{0} ', i)

Next i

Console.WriteLine()

' reverse the array

Array.Reverse(temp)

Console.Write('Reversed Array: ')

For Each i In temp

Console.Write('{0} ', i)

Next i

Console.WriteLine()

'sort the array

Array.Sort(list)

Console.Write('Sorted Array: ')

For Each i In list

Console.Write('{0} ', i)

Next i

Console.WriteLine()

Console.ReadKey()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Original Array: 34 72 13 44 25 30 10Reversed Array: 10 30 25 44 13 72 34Sorted Array: 10 13 25 30 34 44 72

VB.Net - 集合

集合类是用于数据存储和检索的专用类。 这些类提供对堆栈,队列,列表和哈希表的支持。 大多数集合类实现相同的接口。

集合类用于各种目的,例如动态地为元素分配内存以及基于索引访问项目列表等。这些类创建Object类的对象集合,Object类是VB中所有数据类型的基类 。

各种集合类和它们的用法

以下是System.Collection命名空间的各种常用类。 单击以下链接以检查其详细信息。

Class Description and Useage

ArrayList

It represents ordered collection of an object that can be indexedindividually.

它表示可以单独索引的对象的有序集合。

It is basically an alternative to an array. However, unlike array, you can add and remove items from a list at a specified position using anindex and the array resizes itself automatically. It also allows dynamic memory allocation, add, search and sort items in the list.

它基本上是一个数组的替代。 但是,与数组不同,您可以使用索引在指定位置从列表中添加和删除项目,并且数组会自动调整大小。 它还允许动态内存分配,添加,搜索和排序列表中的项目。

Hashtable

It uses a key to access the elements in the collection.

它使用一个键来访问集合中的元素。

A hash table is used when you need to access elements by using key, and you can identify a useful key value. Each item in the hash table has a key/value pair. The key is used to access the items in the collection.

当您需要通过使用键访问元素时使用散列表,您可以标识有用的键值。 散列表中的每个项都有一个键/值对。 该键用于访问集合中的项目。

SortedList

It uses a key as well as an index to access the items in a list.

它使用一个密钥以及索引来访问列表中的项目。

A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index. If you access items using an index, it is an ArrayList, and if you access items using a key, it is a Hashtable. The collection of items is always sorted by the key value.

排序的列表是数组和哈希表的组合。它包含可以使用的键或索引访问的项的列表。如果您访问使用索引的项目,它是一个 ArrayList,和如果你访问项目使用一把钥匙,它是一个哈希表。项的集合总是按关键值排序的。

Stack

It represents a last-in, first out collection of object.

它表示对象的后进先出的集合。

It is used when you need a last-in, first-out access of items. When you add an item in the list, it is called pushing the item, and when you remove it, it is calledpopping the item.

当您需要项目的最后进入,首先访问时使用。 当您在列表中添加项目时,称为推送项目,当您删除它时,它被称为弹出项目。

Queue

It represents a first-in, first out collection of object.

它表示对象的先进先出集合。

It is used when you need a first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque.

当您需要项目的先进先出访问时使用。 当您在列表中添加项目时,它被称为enqueue,当您删除项目时,称为deque。

BitArray

It represents an array of the binary representation using the values 1 and 0.

它表示使用值1和0的二进制表示的数组。

It is used when you need to store the bits but do not know the number of bits in advance. You can access items from the BitArray collection by using an integer index, which starts from zero.

它用于需要存储位但不提前知道位数。 您可以通过使用从零开始的整数索引来访问BitArray集合中的项目。

VB.Net - 函数

过程是一组调用时一起执行任务的语句。执行该过程之后,控制返回到调用过程的语句。 VB.Net有两种类型的程序:

Functions

Sub procedures or Subs

函数返回一个值,而Subs不返回值。

定义函数

函数语句用于声明函数的名称,参数和主体。 函数语句的语法是:

[Modifiers] Function FunctionName [(ParameterList)] As ReturnType

[Statements]

End Function

Modifiers 修饰符 :指定函数的访问级别;可能的值有:公共,私有,保护,朋友,关于保护超载,重载,共享和阴影朋友和信息。

FunctionName:表示该函数的名称

ParameterList 参数列表 :指定参数的列表

ReturnType 返回类型 :指定变量的函数返回的数据类型

示例

以下代码片段显示了一个函数FindMax,它接受两个整数值,并返回两个较大者。Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer' local variable declaration */Dim result As IntegerIf (num1 > num2) Thenresult = num1Elseresult = num2End IfFindMax = resultEnd Function

函数返回值

在VB.Net中,函数可以通过两种方式向调用代码返回一个值:

通过使用return语句

通过将值分配给函数名

下面的例子演示了如何使用FindMax函数:

Module myfunctions

Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer

' local variable declaration */

Dim result As Integer

If (num1 > num2) Then

result = num1

Else

result = num2

End If

FindMax = result

End Function

Sub Main()

Dim a As Integer = 100

Dim b As Integer = 200

Dim res As Integer

res = FindMax(a, b)

Console.WriteLine('Max value is : {0}', res)

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Max value is : 200

递归函数

一个函数可以调用自身。 这被称为递归。 以下是使用递归函数计算给定数字的阶乘的示例:

Module myfunctions

Function factorial(ByVal num As Integer) As Integer

' local variable declaration */

Dim result As Integer

If (num = 1) Then

Return 1

Else

result = factorial(num - 1) * num

Return result

End If

End Function

Sub Main()

'calling the factorial method

Console.WriteLine('Factorial of 6 is : {0}', factorial(6))

Console.WriteLine('Factorial of 7 is : {0}', factorial(7))

Console.WriteLine('Factorial of 8 is : {0}', factorial(8))

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Factorial of 6 is: 720Factorial of 7 is: 5040Factorial of 8 is: 40320

参数数组

有时,在声明函数或子过程时,您不确定作为参数传递的参数的数量。 VB.Net param数组(或参数数组)在这些时候来帮助。

以下示例演示了这一点:

Module myparamfunc

Function AddElements(ParamArray arr As Integer()) As Integer

Dim sum As Integer = 0

Dim i As Integer = 0

For Each i In arr

sum += i

Next i

Return sum

End Function

Sub Main()

Dim sum As Integer

sum = AddElements(512, 720, 250, 567, 889)

Console.WriteLine('The sum is: {0}', sum)

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:The sum is: 2938

传递数组作为函数参数

您可以在VB.Net中将数组作为函数参数传递。 以下示例演示了这一点:

Module arrayParameter

Function getAverage(ByVal arr As Integer(), ByVal size As Integer) As Double

'local variables

Dim i As Integer

Dim avg As Double

Dim sum As Integer = 0

For i = 0 To size - 1

sum += arr(i)

Next i

avg = sum / size

Return avg

End Function

Sub Main()

' an int array with 5 elements '

Dim balance As Integer() = {1000, 2, 3, 17, 50}

Dim avg As Double

'pass pointer to the array as an argument

avg = getAverage(balance, 5)

' output the returned value '

Console.WriteLine('Average value is: {0} ', avg)

Console.ReadLine()

End Sub

End Module

当上述代码被编译和执行时,它产生了以下结果:Average value is: 214.4

VB.Net - Sub过程(子程序)

正如我们在上一章中提到的,Sub过程是不返回任何值的过程。 我们在所有的例子中一直使用Sub过程Main。 到目前为止,我们已经在这些教程中编写控制台应用程序。 当这些应用程序开始时,控制转到主子程序,它反过来运行构成程序主体的任何其他语句。

定义子过程

Sub语句用于声明子过程的名称,参数和主体。 Sub语句的语法是:

[Modifiers] Sub SubName [(ParameterList)]

[Statements]

End Sub

Modifiers 修饰符 :指定过程的访问级别;可能的值有:Public, Private, Protected, Friend, Protected Friend and information regarding overloading, overriding, sharing, and shadowing.

SubName 子名 :表示该子的名字

ParameterList 参数列表 :指定参数的列表

示例

以下示例演示了子过程CalculatePay,它接受两个参数小时和工资,并显示员工的总工资:Sub CalculatePay(ByRef hours As Double, ByRef wage As Decimal)'local variable declarationDim pay As Doublepay = hours * wageConsole.WriteLine('Total Pay: {0:C}', pay)End SubSub Main()'calling the CalculatePay Sub ProcedureCalculatePay(25, 10)CalculatePay(40, 20)CalculatePay(30, 27.5)Console.ReadLine()End SubEnd Module

当上述代码被编译和执行时,它产生了以下结果:

Total Pay: $250.00

Total Pay: $800.00

Total Pay: $825.00

按值传递参数

这是将参数传递给方法的默认机制。 在这种机制中,当调用方法时,为每个值参数创建一个新的存储位置。 实际参数的值被复制到它们中。 因此,对方法中的参数所做的更改对参数没有影响。

在VB.Net中,可以使用ByVal关键字声明引用参数。 下面的例子演示了这个概念:Module paramByvalSub swap(ByVal x As Integer, ByVal y As Integer)Dim temp As Integertemp = x ' save the value of xx = y    ' put y into xy = temp 'put temp into yEnd SubSub Main()' local variable definitionDim a As Integer = 100Dim b As Integer = 200Console.WriteLine('Before swap, value of a : {0}', a)Console.WriteLine('Before swap, value of b : {0}', b)' calling a function to swap the values 'swap(a, b)Console.WriteLine('After swap, value of a : {0}', a)Console.WriteLine('After swap, value of b : {0}', b)Console.ReadLine()End SubEnd Module

当上述代码被编译和执行时,它产生了以下结果:

Before swap, value of a :100

Before swap, value of b :200

After swap, value of a :100

After swap, value of b :200

它表明,虽然它们在函数内部已更改,但值中没有变化。

通过引用传递参数

引用参数是对变量的存储器位置的引用。 当您通过引用传递参数时,与值参数不同,不会为这些参数创建新的存储位置。 参考参数表示与提供给该方法的实际参数相同的存储器位置。

在VB.Net中,可以使用ByRef关键字声明引用参数。 以下示例演示了这一点:Module paramByrefSub swap(ByRef x As Integer, ByRef y As Integer)Dim temp As Integertemp = x ' save the value of xx = y    ' put y into xy = temp 'put temp into yEnd SubSub Main()' local variable definitionDim a As Integer = 100Dim b As Integer = 200Console.WriteLine('Before swap, value of a : {0}', a)Console.WriteLine('Before swap, value of b : {0}', b)' calling a function to swap the values 'swap(a, b)Console.WriteLine('After swap, value of a : {0}', a)Console.WriteLine('After swap, value of b : {0}', b)Console.ReadLine()End SubEnd Module

当上述代码被编译和执行时,它产生了以下结果:

Before swap, value of a : 100

Before swap, value of b : 200

After swap, value of a : 200

After swap, value of b : 100

未完待续,下一章节,つづく

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
c#之——用Convert类实现数据类型转换
.NET基础拾遗(3)字符串、集合和流-(上)
基本的C#面试问题(15例)
ASP.NET2.0 绑定数据字段字符串格式
.net笔试题(多套)
vb.net教程 ArrayList类
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服