Conversion Problems VB Terms Not familiar

Hi everybody,
   I have problem converting this vb.net ocdes into C#. Terms like shared, synclock and friend. What is their exact equivalent in C# I got this sample from another forum. I try to attached the codes.

some codes:

Code:


What is shared in C# in method and variable

Private Shared Function CheckWindowsNT() As Boolean
' ritorna true se e windows NT o 2000 o XP
If Environment.OSVersion.Platform = PlatformID.Win32NT Then Return True
End Function

What is Friend accessor in C#

Friend Sub Add(ByVal zone As CustomTimeZone)
_Zones.Add(zone.ID, zone)
End Sub

What is replacement for SyncLock in C#

If Zones Is Nothing Then
. . .
SyncLock GetType(CustomTimeZone)
.. .
End SyncLock
 

Also,

Public Function GetEnumerator() As System.Collections.IEnumerator Implements
System.Collections.IEnumerable.GetEnumerator
Return _Zones.GetEnumerator
End Function

IN C#, Is this correct

public System.Collections.IEnumerator GetEnumerator : System.Collections.IEnumerable.GetEnumerator
{

return _Zones.getEnumerator();

}



den2005



Answer this question

Conversion Problems VB Terms Not familiar

  • laks_win

    You have to enter VB.NET code into the converter - if you break up lines without the line continuation character, you don't have VB.NET code.

    After changing your first sample converts to VB.NET code, Instant C# produces:

    public static System.DateTime ConvertDateTime(System.DateTime localDate, TimeZone sourceZone, TimeZone targetZone)
    {
    System.DateTime utcDate = DateTime.MinValue;
    utcDate = sourceZone.ToUniversalTime(localDate);
    return targetZone.ToLocalTime(utcDate);
    }

    After changing your second sample to VB.NET code, Instant C# produces:

    public object SyncRoot
    {
      get
      {
      lock(typeof(TimeZonesCollection))
      {
      return this;
      }
      //INSTANT C# NOTE: Inserted the following 'return' since all code paths must return a value in C#:
      return null;
      }
    }

    In general, you need to enter valid syntactically correct source code to get meaningful results (note that it doesn't have to be compilable, just syntactically correct).

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# Converter
    Instant VB: C# to VB.NET Converter
    Instant C++: C# to C++ Converter
    Instant J#: VB.NET to J# Converter
    Clear VB: Cleans up outdated VB.NET code



  • gexaman

    VB Shared -> C# static

    VB Friend -> C# internal

    VB SyncLock ->> C# lock

    public System.Collections.IEnumerator GetEnumerator()
    {
     return _Zones.GetEnumerator();
    }

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# Converter
    Instant VB: C# to VB.NET Converter
    Instant C++: C# to C++ Converter
    Instant J#: VB.NET to J# Converter
    Clear VB: Cleans up VB.NET code



  • Checkup From the Neck Up

    And your third sample converts to:

    public CustomTimeZone this[int index]
    {
     get
     {
      return (CustomTimeZone)(_Zones.GetByIndex(index));
     }
    }

     



  • Vinod Anand

    Thanks for reply David. I also know about this converteer utility and tried the demo version.

    It cannot convert this VB.Net to c#.

    Public Shared Function ConvertDateTime(ByVal localDate As Date, ByVal
    sourceZone As TimeZone, ByVal targetZone As TimeZone) As Date
    Dim utcDate As Date
    utcDate = sourceZone.ToUniversalTime(localDate)
    Return targetZone.ToLocalTime(utcDate)
    End Function

    Result is:

    //TODO: INSTANT C# TODO TASK: The following line could not be converted:

    Public Shared Function ConvertDateTime(ByVal localDate As Date, ByVal

    sourceZone As TimeZone, ByVal targetZone As TimeZone) As System.DateTime;

    System.DateTime utcDate = DateTime.MinValue;

    utcDate = sourceZone.ToUniversalTime(localDate);

    return targetZone.ToLocalTime(utcDate);

    }

    Another VB.net code to c#:

    [vb]

    Public ReadOnly Property SyncRoot() As Object Implements
    System.Collections.ICollection.SyncRoot
      Get
         SyncLock GetType(TimeZonesCollection)
            Return Me
         End SyncLock
      End Get
    End Property

    Result in C#:

    public object Implements SyncRoot

    {

    System.Collections.ICollection.SyncRoot;

    get

    {

    lock(typeof(TimeZonesCollection))

    {

    return this;

    }

    //INSTANT C# NOTE: Inserted the following 'return' since all code paths must return a value in C#:

    return null;

    }

    }

    Is this correct

    So, I hope after I converted this no problem.

    den2005

     


  • great_ghost

    Another limited capability of this converter.

    VB:

    Default Public ReadOnly Property Item(ByVal index As Integer) As
    CustomTimeZone
    Get
    Return CType(_Zones.GetByIndex(index), CustomTimeZone)
    End Get
    End Property

    C# Result:

    //TODO: INSTANT C# TODO TASK: The following line could not be converted:

    public Default ReadOnly Property Item(ByVal index As Integer) As

    CustomTimeZone;

    get

    {

    return (CustomTimeZone)(_Zones.GetByIndex(index));

    }

    }

    Hope anyone know how this codes can be converted properly.

    den2005


  • Conversion Problems VB Terms Not familiar