共用方式為


= 運算子 (Visual Basic)

將值指派給變數或屬性。

語法

variableorproperty = value  

組件

variableorproperty
任何可寫入的變數或任何屬性。

value
任何常值、常數或表達式。

備註

等號 (=) 左邊的專案可以是簡單的純量變數、屬性或陣列的專案。 變數或屬性不可以是 ReadOnly。 運算子 = 會將右邊的值指派給其左邊的變數或屬性。

備註

運算子 = 也會當做比較運算符使用。 如需詳細資訊,請參閱 比較運算符

重載

運算子 = 只能多載為關係比較運算元,而不是指派運算符。 如需詳細資訊,請參閱 運算符程式

範例

下列範例示範指派運算符。 右邊的值會指派給左邊的變數。

Dim testInt As Integer
Dim testString As String
Dim testButton As System.Windows.Forms.Button
Dim testObject As Object
testInt = 42
testString = "This is an example of a string literal."
testButton = New System.Windows.Forms.Button()
testObject = testInt
testObject = testString
testObject = testButton

另請參閱