Author Topic: Translating C#  (Read 1843 times)

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Translating C#
« on: December 27, 2019, 02:47:56 PM »
How'd you translate these C# codes to VB? Thanks.
Code: [Select]
private static Settings _instance;
public static Settings Instance
        {
            get { return _instance ?? (_instance = new Settings()); }
        }

Code: [Select]
Private Shared _instance As Settings   
Public Shared ReadOnly Property Instance As Settings
        Get
            If (_instance Is Nothing) Then
                _instance = New Settings
            End If
           
            Return _instance
        End Get
End Property
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Translating C#
« Reply #1 on: December 27, 2019, 03:08:16 PM »
Your 2nd code is a translated 1st code.

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Translating C#
« Reply #2 on: December 27, 2019, 04:05:20 PM »
Your 2nd code is a translated 1st code.
Thank you for verifying that! I wasn't so sure.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Translating C#
« Reply #3 on: December 27, 2019, 06:40:53 PM »
Your translation is elegant unlike what online converters offer as a translation for that C# code.
« Last Edit: December 27, 2019, 06:51:10 PM by Godra »

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
MJ101: Event translation
« Reply #4 on: December 28, 2019, 10:20:57 AM »
This is one I keep forgetting:
Code: [Select]
//Add event handlers
                txtSQLServerName.TextChanged += BuildConnectionString;

Code: [Select]
AddHandler txtSQLServerName.TextChanged,  AddressOf BuildConnectionString
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
MJ102: Form events order
« Reply #5 on: December 28, 2019, 10:36:44 AM »
In C# application, any statement/ sub routines that put right after InitializeComponent() will get execute BEFORE form_move and form_load events.

in VB, select view code, select middle drop down Form , select right side drop down New.
Code: [Select]
Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        DoEventFirst()

        ' Add any initialization after the InitializeComponent() call.
End Sub
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================