• (2 Pages)
  • +
  • 1
  • 2

What does this error mean? Understanding the common errors.

#16 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10396
  • View blog
  • Posts: 38,463
  • Joined: 27-December 08

Posted 11 March 2013 - 06:03 PM

The following are all different languages: C, C++, Objective-C, C#. This is the C# tutorials section, which is a .NET language.
Was This Post Helpful? 0
  • +
  • -

#17 Stack01  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 12
  • Joined: 07-May 14

Posted 07 May 2014 - 05:25 PM

Hi, I have a total beginner question.

In your example where you write,

namespace jellystone
{
     public class picnic
     {
          public Object basket;  // This exists only within the picnic
          public NumberOfSandwiches = 6;
           void someMethod()
           {
                 int x;
           }

           void anotherMethod()
           {
                 int x;  // NOT the same x as in someMethod()
           }
     }


      class Ranger
      {
           void different method()
           int count = basket.NumberOfSandwiches;  // basket is unknown here. Undefined in the context of this method of this class
      }
}





I was wondering how would you get SomeMethod() and AnotherMethod() to talk to each other then? That is, if x is equal to a list of items, how would you pass that to anotherMethod() keeping the same values (list in this case)?

Thanks!
Was This Post Helpful? 0
  • +
  • -

#18 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Posted 08 May 2014 - 05:34 PM

I wouldn't have someMethod() and anotherMethod() talk to each other. That's generally bad. Each method has a single purpose with no side effects and we like that. If you tie them together then it becomes imposssible to call someMethod() without the side effects caused by it calling another Method().

In your program that uses Picnic class you could create a method that calls one then the other.

class Controller
{
     void DoSomeComplexFunction()
     {
         Picnic p = new Picic();
         var answer = p.someMethod();
         var result = p.anotherMethod(answer);//Take the answer from first method and send it as a parameter to the second method
         DisplayTotal(result);
     }
}


I think this tutorial should help you get a start on planning a program
http://www.dreaminco...ister-part-one/
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2