C#
TopAuthor author = new TopAuthor();
//No "With" construct
author.Name = "Steven";
author.AuthorRanking = 3;
author.Rank("Scott");
TopAuthor.Demote() //Calling static method
TopAuthor author2 = author //Both refer to same object
author2.Name = "Joe";
System.Console.WriteLine(author2.Name) //Prints Joe
author = null //Free the object
if (author == null)
author = new TopAuthor();
Object obj = new TopAuthor();
if (obj is TopAuthor)
SystConsole.WriteLine("Is a TopAuthor object.");
Structs
VB.NET
Structure AuthorRecord
Public name As String
Public rank As Single
Public Sub New(ByVal name As String, ByVal rank As Single)
Me.name = name
Me.rank = rank
End Sub
End Structure
Dim author As AuthorRecord = New AuthorRecord("Steven", 8.8)
Dim author2 As AuthorRecord = author
author2.name = "Scott"
System.Console.WriteLine(author.name) 'Prints Steven
System.Console.WriteLine(author2.name) 'Prints Scott
C# struct AuthorRecord {
public string name;
public float rank;
public AuthorRecord(string name, float rank) {
this.name = name;
this.rank = rank;
}
}
AuthorRecord author = new AuthorRecord("Steven", 8.8);
AuthorRecord author2 = author
author.name = "Scott";
SystemConsole.WriteLine(author.name); //Prints Steven
System.Console.WriteLine(author2.name); //Prints Scott
Properties
VB.NET
Private _size As Integer
Public Property Size() As Integer
Get
Return _size
End Get
Set (ByVal Value As Integer)
If Value < 0 Then
_size = 0
Else
_size = Value
End If
End Set
End Property
foo.Size += 1
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] 下一页
|