0

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 ?

Peter
  • 2,043
  • 1
  • 21
  • 45

1 Answers1

1

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.

sr28
  • 4,728
  • 5
  • 36
  • 67
  • hm adding static like 'public static SortedDictionary> ResizeDataSet(SortedDictionary – Peter Mar 11 '16 at 16:29
  • Well that depends on how it's going to be used. There's no hard and fast rule. Hopefully this will help: http://stackoverflow.com/questions/241339/when-to-use-static-classes-in-c-sharp If your initial problem has been fixed then please mark this as the answer. – sr28 Mar 11 '16 at 16:39
  • ah i think i understand now, the graphics class is al surounded around a graphical object (main code creates an instance of it), while the Math functions are just functions, not objects.. – Peter Mar 11 '16 at 16:44