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. Moving from validation function to validation read only Property

Moving from validation function to validation read only Property

Scheduled Pinned Locked Moved C#
question
3 Posts 3 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
    abcurl
    wrote on last edited by
    #1

    Hi, I was writing a validation function. Which is as follows

    private void IsFolderValid1()
    {
    return false;
    }

    and somebody suggested me to write it in following way.

    private void IsFolderValid1()
    {
    Get
    {
    return false;
    }
    }

    Can u please explain me the reason. Whether it is right or wrong ? Thanks

    L L 2 Replies Last reply
    0
    • A abcurl

      Hi, I was writing a validation function. Which is as follows

      private void IsFolderValid1()
      {
      return false;
      }

      and somebody suggested me to write it in following way.

      private void IsFolderValid1()
      {
      Get
      {
      return false;
      }
      }

      Can u please explain me the reason. Whether it is right or wrong ? Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Your first version is right. Getters and Setters should be used for properties.

      1 Reply Last reply
      0
      • A abcurl

        Hi, I was writing a validation function. Which is as follows

        private void IsFolderValid1()
        {
        return false;
        }

        and somebody suggested me to write it in following way.

        private void IsFolderValid1()
        {
        Get
        {
        return false;
        }
        }

        Can u please explain me the reason. Whether it is right or wrong ? Thanks

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, none of that is correct, for several reasons: 1. if a property or method returns "false" its type should be boolean, not void. 2. property and method names normally shouldn't contain digits 3. method names normally contain a verb, and property names may or may not (preferably not, although IsValid would be acceptable) 4. private members use pascalCase, public ones CamelCase. 5. properties should always be public (protected could be OK, private is a bit strange). 6. properties don't take parentheses. So choose one of these:

        public boolean IsFolderValid() { ... return false;}

        public boolean FolderValid {
        get { ... return false; }
        }

        :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        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