OK, so let’s bring this baby in for a landing!

GENERIC METHODS

According to the SoloLearn app, generics allow the reuse of code across different types. To demonstrate this, let’s first declare a method that swaps the values of two parameters:

static void Swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}

As a reminder for myself, I decided to look up ref as it was the only thing in the above code that I couldn’t remember. …


We’re on a roll now, so let’s keep going (he awkwardly said to himself)…

STRUCTS

A struct type is a value type that encapsulates small groups of related variables like the coordinates of a rectangle, or the characteristics of an item in an inventory. A struct is declared like this:

struct Book {
public string title;
public double price;
public string author;
}

OK, so here we go, new stuff!

ABSTRACT CLASSES

We’re going to talk about something called Abstract Classes, but the SoloLearn app first reviews what we just went through, polymorphism. It states that it’s:

Used when you have different derived classes with the same method, which has different implementations in each class. This behavior is achieved through virtual methods that are overridden in the derived classes.

In other words, where a base class has methods that are inherited by a derived class, you can have a method in the derived class overwrite a method of the same name from the…


INHERITANCE

Next up, we go into the Inheritance & Polymorphism section of the SoloLearn app. We definitely talked about polymorphism early on, so I’m hoping to understand that pretty well when we get to it. First, though, we’ll talk about inheritance. The is the ability to define one class based on another class. Apparently, this…

…makes creating and maintaining an application easy.

Mm hmm.

The class whose properties are being inherited by another class is called the base class. The class that is doing the “inheriting” is called the derived class. Their example describes it pretty well:

…base class Animal can…


THIS

Next up, the SoloLearn app goes through the this keyword, which refers to the current instance of the class, or, the current object. One important thing that they point out is using it to distinguish class members from other data like local variables of a method.

Here’s an example:

class Person {
private string name;
public Person(string name) {
this.name = name;
}
}

In the code above, this is described within the app this way:

Here, in this.name, this represents the member of the class, whereas name represents the parameter of the constructor.


DESTRUCTORS

The SoloLearn app now goes into what, effectively, is the opposite of a constructor (which is the instantiation of a class), which is a destructor. Destructors are automatically invoked when an object is destroyed or deleted. They then list the following four attributes of destructors:

  • A class can only have one destructor.
  • Destructors cannot be called. They are invoked automatically.
  • A destructor does not take modifiers or have parameters.
  • The name of the destructor is exactly the same as the name of the class, prefixed with a tilde (~), as in the following:
class Dog {…

JAGGED ARRAYS

Continuing on with Arrays & Strings, we’re going to purposely give ourselves a headache, by talking about jagged arrays. Apparently, “jagged” arrays are arrays of arrays. Here’s what the code looks like:

int[ ][ ] jaggedArr = new int[3][ ];

This code declares a new single-dimensional array called jaggedArr, who has 3 elements, each of which is a single-dimensional array of integers. So, above is how you’d create the jagged array but without any initial values. Below is code that creates a jagged array with initial values. …


I just finished Part 6 about 5 or 10 minutes ago, but I’ve got some momentum now and decided to just move right along to the next section within the SoloLearn app, called Arrays & Strings.

ARRAYS

In as much as we can create new classes, there are a number of built-in classes, one of which is the array class. The app describes it this way:

An array is a data structure that is used to store a collection of data. You can think of it as a collection of variables of the same type.

A simple example of when and…


OK, so moving on…

…we now find ourselves within the Classes & Objects section. They haven’t really touched on anything related to classes yet, but we have seen them. While they’ve talked about using individual variables, of a data type, which can hold single values, classes are described as:

A data type that defines a set of variables and methods for a declared object.

I really like the way they explain what a class is in that you could have a class called BankAccount which has properties and methods for managing an individual bank account (i.e. balance, deposit, withdrawal, etc.)…


The first sentence of the project within the SoloLearn app says:

Now, let’s create a method that will display a pyramid of any height to the console window using star (*) symbols.

…and I start to get queasy…

I’ve got Visual Studio launched, and a new Console App called StarPyramid made. I’ve erased the sample code within the Main method, and stare…

Here are my thoughts:

  • There will be a loop that repeats based on the number of rows that the user enters.
  • The first row will print 1 star to the screen, and then each subsequent row will take…

Scott Rosenbloom

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store