Search code examples
c#oopfunctional-programming

Is the c# a functional or object oriented language?


Is the c# a functional or object oriented language?

I need to learn writing very good code using c#, but should I use C# primarily as a functional language or object orientated?

I'm confused should I use OOP coding style or functional coding style. or should I mix between them.


Solution

  • From wikipedia:

    C# is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines

    So, in general, we can just use whichever paradigm suits our needs for the task at hand.

    UPDATE: A couple of caveats have been highlighted by the comments below:

    • It is primarly intended to be "a simple, modern, general-purpose, object-oriented programming language" which means that the functional paradigm plays second fiddle to the object oriented one.
    • As a result some concepts considered important for functional programming are missing such as tail recursion
    • We can also change a mutable state via too many avenues to guarantee functional programming without side-effects. We therefore ought to excercise a little caution when using a functional paradigm not to alter state (for example by ensuring we are not changing an object in a LINQ Select statement)