Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. VB to C# conversion. Implements

VB to C# conversion. Implements

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aalex675
    wrote on last edited by
    #1

    I am converting a class from VB to C# so that it can be compiled into the same assembly, but have run into something that I don't know how to handle. The class is a generic ObservableDictionary. My problem is that I don't know how to implement both System.Collections.Generic.IEnumerable.GetEnumerator and System.Collections.IEnumerable.GetEnumerator since both of them need an exposed function named GetEnumerator(). The VB code is as follows:

    Public Function GetEnumerator()
    As System.Collections.Generic.IEnumerator(
    Of System.Collections.Generic.KeyValuePair(Of TKey, TValue))
    Implements System.Collections.Generic.IEnumerable(
    Of System.Collections.Generic.KeyValuePair(Of TKey, TValue)).GetEnumerator

    Return DirectCast(Dictionary, IDictionary).GetEnumerator()
    

    End Function

    Private Function GetEnumerator1()
    As System.Collections.IEnumerator
    Implements System.Collections.IEnumerable.GetEnumerator

    Return GetEnumerator()
    

    End Function

    It looks to me like the VB code is renaming the GetEnumerator function to GetEnumerator1 and explicitly mapping this back to the GetEnumerator function that is being implemented, but I have never seen anything like this in C#. Is this possible in C#?

    I 1 Reply Last reply
    0
    • A aalex675

      I am converting a class from VB to C# so that it can be compiled into the same assembly, but have run into something that I don't know how to handle. The class is a generic ObservableDictionary. My problem is that I don't know how to implement both System.Collections.Generic.IEnumerable.GetEnumerator and System.Collections.IEnumerable.GetEnumerator since both of them need an exposed function named GetEnumerator(). The VB code is as follows:

      Public Function GetEnumerator()
      As System.Collections.Generic.IEnumerator(
      Of System.Collections.Generic.KeyValuePair(Of TKey, TValue))
      Implements System.Collections.Generic.IEnumerable(
      Of System.Collections.Generic.KeyValuePair(Of TKey, TValue)).GetEnumerator

      Return DirectCast(Dictionary, IDictionary).GetEnumerator()
      

      End Function

      Private Function GetEnumerator1()
      As System.Collections.IEnumerator
      Implements System.Collections.IEnumerable.GetEnumerator

      Return GetEnumerator()
      

      End Function

      It looks to me like the VB code is renaming the GetEnumerator function to GetEnumerator1 and explicitly mapping this back to the GetEnumerator function that is being implemented, but I have never seen anything like this in C#. Is this possible in C#?

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #2

      Yep. I was going to type it all out, but that's a lot of typing... Heh VB:

      Public Function DoSomething() Implements A.B.C.DoSomething

      End Function

      C#:

      public void A.B.C.DoSomething()
      {
      }

      EDIT: There's a shortcut, by the way... Right-click the interface in the class definition, and pick "Implement Interface Explicitly"

      Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups