Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

properties and invoking a method...

Posted on 2006-11-27
6
Medium Priority
?
219 Views
Last Modified: 2010-04-16
As I research, I'm trying to find out how to invoke a method from a property.  Maybe I'm not quite understanding the logic behind it, however, the examples I see have methods set to Public.  I'm not going crazy am I.  If it's public, what's the sense in invoking a method from the property..  I'm developing my own library, and I only want to provide property level access, etc.

I want to pass a string to a property, call a method from within that property, and pass back an array of strings to pick and choose for use.

Any suggestions?

0
Comment
Question by:scorp8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 18023515
Well, I would tend to agree with you - making the method and the property both public doesn't make any sense. You can make the method private and still call from the property.

HOWEVER, as a good coding practice I tend to keep all my properties light - i.e. they especially don't call process intensive methods when accessed. This is becauase the consumer of the class (3rd party integrator, another member of the dev team, etc...) can safely assume that calling a property will be fast and will not cause an overhead if used in a tight loop, whereas calling a method usually involves some kind of processing overhead. Usually my properties simply return a private variable.
0
 
LVL 1

Expert Comment

by:Epurchase
ID: 18027476
Whenever you want to do some operation (either intensive or not), You must expose through methods. Properties should only be used for characteristics of your object.

However, You could create a class with a string and array of string say it "ParamClass".
Set the property type ParamClass. like that

public ParamClass MyProperty
{
    get { ... }
    set { ... }
}
0
 
LVL 1

Author Comment

by:scorp8
ID: 18028119
What is a good way to pass a string into a property, invoke a method,  then return an array?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 29

Expert Comment

by:Nightman
ID: 18028946
Do it through the method directly:

public Array ReturnMyArray(string MyInputString)
{
   //do some processing
   return MyArrayVariable;
}
0
 
LVL 1

Author Comment

by:scorp8
ID: 18039494
I don't want to expose my method as public, I'd rather expose the property and invoke the method from my property.
0
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
ID: 18041213
Then you would do something like this:

    private string _myString;
    public string MyString
    {
      get
      {
        return _myString;
      }
      set
      {
        _myString=value;
      }
    }
    public Array ReturnMyArray
    {
      get
      {
        //do some processing
        return GenerateMyArray(_myString);
      }
    }
    private Array GenerateMyArray(string MyString)
    {
      Array MyArrayVariable;
      //do some processing
      return MyArrayVariable;
    }      //

You would have to set the property MyString first via the property, and then when you call the ReturnMyArray property it will call the private method passing in the string.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question