Results 1 to 5 of 5

Thread: new constructor in a struct? how ?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Talking new constructor in a struct? how ?

    me and my stupid questions
    how do you declare the new constructor in a struct,... I just want an example
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    VB Code:
    1. Structure MyStruct
    2.    Private Shared x As Integer = 25
    3.    Private Shared y As Integer = 50
    4.  
    5.  
    6.    Public Sub SetXY(i As Integer, j As Integer)
    7.       x = i
    8.       y = j
    9.    End Sub 'SetXY
    10.  
    11.    Public Shared Sub ShowSum()
    12.       Dim sum As Integer = x + y
    13.       Console.WriteLine("The sum is {0}", sum)
    14.    End Sub 'ShowSum
    15. End Structure 'MyStruct
    16.  
    17. Class MyClient
    18.  
    19.    Public Shared Sub Main()
    20.       Dim ms As New MyStruct()
    21.       ms.SetXY(100, 200)
    22.       MyStruct.ShowSum()
    23.    End Sub 'Main
    24.  
    25. End Class 'MyClient
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Memnoch1207
    VB Code:
    1. Structure MyStruct
    2.    Private Shared x As Integer = 25
    3.    Private Shared y As Integer = 50
    4.  
    5.  
    6.    Public Sub SetXY(i As Integer, j As Integer)
    7.       x = i
    8.       y = j
    9.    End Sub 'SetXY
    10.  
    11.    Public Shared Sub ShowSum()
    12.       Dim sum As Integer = x + y
    13.       Console.WriteLine("The sum is {0}", sum)
    14.    End Sub 'ShowSum
    15. End Structure 'MyStruct
    16.  
    17. Class MyClient
    18.  
    19.    Public Shared Sub Main()
    20.       Dim ms As New MyStruct()
    21.       ms.SetXY(100, 200)
    22.       MyStruct.ShowSum()
    23.    End Sub 'Main
    24.  
    25. End Class 'MyClient
    hey it's the C# forum not VB.NET!

    I figued it out anyways, thanks... I was declaring it as void thinking that its like the old C's void main
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    sorry, I haven't done it in C# yet!
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Code:
    public struct MyStruct
    {
        private string _myVar;
        public string MyVar
        {
            get { return _myVar; }
            set { _myVar = value; }
        }
    
        public MyStruct(string myVarInit)
        {
            _myVar = myVarInit;
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width