-1

i was wondering, what kind of method i should be using

public class UserProfile {

    public String GetAsString(){
        ... Some Stuff
        return anyString;
    }

    // Or this one
    public static String GetAsString(UserProfile profile){
        ... Some Stuff
        return anyString;
    }
}

Are there any performance issues, or anything i should be using one of these methods?

Thanks for helping me

DirtyNative
  • 2,553
  • 2
  • 33
  • 58

1 Answers1

0

In an object-oriented language like C# your primary choice should be always instance members over static members.

Static members...

  • ...are part of no instance.
  • ...can't be polymorphic (i.e. virtual).
  • ...can't access instance members. So, it's all or nothing if you thought you could mix static and instance members just because of performance issues (although instance members can access static members...).

Actually, the main issue with using statics in terms of software architecture is that they turn classes into just modules or containers of functions instead of considering classes as archetypes of objects.

Statics are good to implement factory methods, constants, singletons and some other requirements, but they shouldn't be considered as an alternative to pure object-oriented programming per se.

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206