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. Convert Properties in vb6 to C#

Convert Properties in vb6 to C#

Scheduled Pinned Locked Moved C#
csharpquestion
4 Posts 3 Posters 2 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.
  • J Offline
    J Offline
    Jimmy Beh
    wrote on last edited by
    #1

    Private objTestStr As String

    Public Property Get TestStr() As String
    Set TestStr = objTestStr
    End Property

    how will the code looks like in c#?

    W B 2 Replies Last reply
    0
    • J Jimmy Beh

      Private objTestStr As String

      Public Property Get TestStr() As String
      Set TestStr = objTestStr
      End Property

      how will the code looks like in c#?

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      In C# you can create a Property in multiple ways : Full blown Property :

      private string testString;
      public string TestString
      {
      get
      {
      return testString;
      }
      set
      {
      testString = value;
      //Generally when you use full blown properties
      //you do so because you need to do some sort of
      //validation or other testing or to set other
      //properties or fields as well
      }
      }

      Or you can use Auto Implemented Properties:

      public string TestString { get; set; };

      For a good explanation of C# properties see the MSDN page here[^]

      Everyone dies - but not everyone lives

      J 1 Reply Last reply
      0
      • W Wayne Gaylard

        In C# you can create a Property in multiple ways : Full blown Property :

        private string testString;
        public string TestString
        {
        get
        {
        return testString;
        }
        set
        {
        testString = value;
        //Generally when you use full blown properties
        //you do so because you need to do some sort of
        //validation or other testing or to set other
        //properties or fields as well
        }
        }

        Or you can use Auto Implemented Properties:

        public string TestString { get; set; };

        For a good explanation of C# properties see the MSDN page here[^]

        Everyone dies - but not everyone lives

        J Offline
        J Offline
        Jimmy Beh
        wrote on last edited by
        #3

        does the vb code above includes both the Get and Set? or its just a readonly Property where is should only include Get?

        1 Reply Last reply
        0
        • J Jimmy Beh

          Private objTestStr As String

          Public Property Get TestStr() As String
          Set TestStr = objTestStr
          End Property

          how will the code looks like in c#?

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Your code shows a read-only property.

          private string objTestStr;
          public string TestStr
          {
          get { return objTestStr; }
          }

          Well, naming conventions differ a little, _TestString would be preferred instead of objTestStr. You could also use:

          public string TestStr { get; private set; }

          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