2

I transitioned from js to c# about 4 weeks ago for my first job in the industry. It has been a really rough 3 weeks for someone who hasn't had any OOP experience. I've been trying really hard to ramp up, but I'm having a really hard time wrapping my head around some of the advance c# topics (e.g. interface, extension methods, etc.) Does anyone have good resources or advice to help me get my feet wet?

Comments
  • 2
    I found pluralsight very helpful in picking up C#.

    There’s... well there used to be a free subscription part of the http://developer.microsoft.com signup.
  • 1
    Think of an interface as a promise. (Not to be confused
    with js promise and async)

    Your function asks for an interface and the object implements the interface, promising to provide the required functions.

    Many different objects can provide the same interface without having anything to do with each other and can do quite different things but all will be valid for your function.

    Its a way to disconnect part so they can be developed separately or to make it easy to reuse.
  • 1
    Extension methods are just syntactic sugar.

    Instead of writing:

    MyGlobalStatic.DoStuff(yourObject)

    You can write

    yourObject.DoStuff()

    And with god intellisense the method will show up on writing the . which makes discovery of the method easier, you do not need to know where it is defined.
  • 2
    Interfaces are just a way to refer to multiple classes at once. Eg. You have many similar classes (EditableLabel, EditableLabelSegmented, EditableCalendar, etc.) which you want to get as input to a method, without knowing which one exactly. Thus, you can create an interface called "EditableWidget", which will give you the ability to use some of the fields/methods that the previous classes had in common. In the interface you define what's common by defining the common method's/field's signature with the keyword "abstract". Now each of the classes that implement that interface will have to have those fields/methods. Afterwards you can say:
    public void printText (EditableWidget widget) {
    print (widget.getText ());
    }
    And you don't really care what that widget is exactly, you just want to print it's text. That saves you time and readability, since you don't have to write the same method for each one of the similar classes, just because they are different classes. You write once for all.
Add Comment