me and my stupid questions
how do you declare the new constructor in a struct,... I just want an example:D
Printable View
me and my stupid questions
how do you declare the new constructor in a struct,... I just want an example:D
VB Code:
Structure MyStruct Private Shared x As Integer = 25 Private Shared y As Integer = 50 Public Sub SetXY(i As Integer, j As Integer) x = i y = j End Sub 'SetXY Public Shared Sub ShowSum() Dim sum As Integer = x + y Console.WriteLine("The sum is {0}", sum) End Sub 'ShowSum End Structure 'MyStruct Class MyClient Public Shared Sub Main() Dim ms As New MyStruct() ms.SetXY(100, 200) MyStruct.ShowSum() End Sub 'Main End Class 'MyClient
hey it's the C# forum not VB.NET!:D:DQuote:
Originally posted by Memnoch1207
VB Code:
Structure MyStruct Private Shared x As Integer = 25 Private Shared y As Integer = 50 Public Sub SetXY(i As Integer, j As Integer) x = i y = j End Sub 'SetXY Public Shared Sub ShowSum() Dim sum As Integer = x + y Console.WriteLine("The sum is {0}", sum) End Sub 'ShowSum End Structure 'MyStruct Class MyClient Public Shared Sub Main() Dim ms As New MyStruct() ms.SetXY(100, 200) MyStruct.ShowSum() End Sub 'Main End Class 'MyClient
I figued it out anyways, thanks... I was declaring it as void thinking that its like the old C's void main :)
sorry, I haven't done it in C# yet! :D :D
Code:public struct MyStruct
{
private string _myVar;
public string MyVar
{
get { return _myVar; }
set { _myVar = value; }
}
public MyStruct(string myVarInit)
{
_myVar = myVarInit;
}
}