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. how to declare a method for a property

how to declare a method for a property

Scheduled Pinned Locked Moved C#
questiontutorial
4 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.
  • M Offline
    M Offline
    mehran asg
    wrote on last edited by
    #1

    hi. in DateTime.Now , Now is a property. But when we set a dot after Now we can see a list of methods and properties, such as DateTime.Now.AddDay() , DateTime.Now.Date , DateTime.Now.AddMonth() how can I do it? thanks mehran

    A M 2 Replies Last reply
    0
    • M mehran asg

      hi. in DateTime.Now , Now is a property. But when we set a dot after Now we can see a list of methods and properties, such as DateTime.Now.AddDay() , DateTime.Now.Date , DateTime.Now.AddMonth() how can I do it? thanks mehran

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      If you have looked carefully at the type returned by the Now property, you might have seen that it's a DateTime object, which has properties and methods. So if you want to create a property that "has methods" you just need to create a property that returns an object that has other properties and methods. Hope it helps.

      I will use Google before asking dumb questions

      M 1 Reply Last reply
      0
      • A Andrei Ungureanu

        If you have looked carefully at the type returned by the Now property, you might have seen that it's a DateTime object, which has properties and methods. So if you want to create a property that "has methods" you just need to create a property that returns an object that has other properties and methods. Hope it helps.

        I will use Google before asking dumb questions

        M Offline
        M Offline
        mehran asg
        wrote on last edited by
        #3

        so thakns.

        1 Reply Last reply
        0
        • M mehran asg

          hi. in DateTime.Now , Now is a property. But when we set a dot after Now we can see a list of methods and properties, such as DateTime.Now.AddDay() , DateTime.Now.Date , DateTime.Now.AddMonth() how can I do it? thanks mehran

          M Offline
          M Offline
          MohammadAmiry
          wrote on last edited by
          #4

          This is so simple! DateTime.Now is of type of class 'Date' which has itself different properties and methods! You can create a class, and add any methods or properties in that class. In an other class, now you may have a property of the latter class type.

          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