Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:03:52+00:00 2026-06-08T00:03:52+00:00

I have a demo script which shows the question quite nicely so I will

  • 0

I have a demo script which shows the question quite nicely so I will show the script, then ask.

class Program
{
    static void Main(string[] args)
    {
        Dog dog = new Dog() { Age = 4 };

        //This approach (version A)
        dog.DisplayDogYears();

        //Or this approach (version B)
        displayDogYears(dog);

        Console.ReadKey();
    }

    private static void displayDogYears(Dog d)
    {
        Console.WriteLine("The dog is {0} years old in human years.", d.Age * 7);
    }
}

public class Dog
{
    public int Age { get; set; }

    public void DisplayDogYears()
    {
        Console.WriteLine("The dog is {0} years old in human years.", Age * 7);
    }
}

There are 2 approaches which do the same thing (approach A and B). Are there any reasons to prefer one approach over another, in terms of scalability and readable code. I can see one advantage of the approach A is that this method is available to all instances of the Dog class (so nice and scalable and reusable and maintainable, however, when debugging it does mean I have to move between different classes (and VS has to jump to different files etc) instead of viewing everything in just one file.

Any thoughts?

Dave

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:03:53+00:00Added an answer on June 8, 2026 at 12:03 am

    I would prefer to have a method in the class Dog:

    public int GetAgeInHumanYears()
    {
        return Age*7;
    }
    

    and call this method from the main with a format string you like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tested the below script on a demo page which is not using
I have: <script> $(function() { $( #datepicker ).datepicker(); }); </script> <div class=demo> <p>Date: <input
I have a script which uses ajax(json) to fetch Google suggestions(xml), demo: JsFiddle I
i have this http://pastie.org/836744 script, which works outside the class completely fine, but it
I have this script which allows to display Bing search results: JsFiddle Demo The
I have got a demo script that lets me authorize with my app and
I have the Demo Table which I can click on the cell(td tag) and
I have a demo app which is supposed to be an example of creating
I have one demo application to check select for update query public class Test
I have a pagination script, which can be seen here: http://www.automotori6282.tk/phpsandbox/ This is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.