Peter
Peter

Reputation: 2267

Calling method from different class in same library, errors about object reference

I wrote code for a new library, most of the code is located under

public class Locked

Most graphical functions are in there. However i also provide some specific exotic maths as a separate name-space in the same dll as Magic Math, those functions are not private just as public as every function under Locked.

public class MagicMath

Some functions inside the Locked class require the MagicMath So i call them as

MagicMath.ResizeDataSet(...

This gives an error An object reference is required for the non-static field, method, or property

   'MagicMath.ResizeDataSet( SortedDictionary <int, List<int>>, int, int)'  

I'm kinda confused here, as those functions in MagicMath are recognised, their parameters gets accepted, i only get a redline under the function text (ResizeDataSet) when called from within code in the class Locked.. Whats wrong ?

Upvotes: 0

Views: 124

Answers (1)

sr28
sr28

Reputation: 5156

You can either set the methods inside 'Locked' that call 'MagicMath' to static as well as the MagicMath methods that are called or create an instance of MagicMath.

See what static means and when to use it in the words of Microsoft.

Use the static modifier to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with classes, fields, methods, properties, operators, events, and constructors, but it cannot be used with indexers, destructors, or types other than classes.

Upvotes: 1

Related Questions