C# in Simple Terms - Classes and Members

C# in Simple Terms - Classes and Members

Now that we have discussed the type system, primitive types, operators, methods, and basic statements and loops, we can start to learn about the defining characteristic of C# and object-oriented programming in general: classes.


class _in C## is a definition that can be used to create _instances of that class. Classes are created using the class keyword. C## classes are always reference types.

class TestClass 
    //An empty C## class

By convention, C## classes use Pascal Naming; each word in the class name should have their first letter capitalized.


Classes can have members. Members are any objects in a class that are part of the class definition; everything defined in a class is a member of that class. This includes:

  • Fields - Members of the class that hold values and must be accessed directly. Each of these will have a type.
  • _Properties _- Members of the class which provides a way to read, write, or change a value held by a field.
  • _Methods _- A code block containing a set of statements that will be executed. Methods may or may not return a value of a given type.
  • _Constructors _- A special kind of method which sets the initial values for the properties in the class.

Class Instances

We create an instance of a class using the new keyword:

var myInstance = new TestClass();

We can then manipulate the instance by changing its property values, invoking methods or constructors, etc.

c# in simple terms c++

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

C# in Simple Terms - Operators

Let's continue our C# in Simple Terms series with one of the basic parts of any line of code: the operators.

C# in Simple Terms - Structs and Enums

Now that we understand a little more about classes and previously learned the difference between value types and reference types, it's time to explore some more specialized C# types. In today's edition of C# in Simple Terms, let's explore two useful value types: structs and enums.

Introducing C# in Simple Terms!

In the past, we have used mega-series to tackle big subjects such as design patterns, anti-patterns, and sorting algorithms. In this series, we're going back to basics to discover, learn, and teach the programming language we all know and love: C#!

C# in Simple Terms - Inheritance and Polymorphism

Now that we've discussed most of the basics we need for a C# program, let's talk about two concepts that are central to how C# (and indeed, all object-oriented programming languages) work: inheritance and polymorphism.

C# in Simple Terms - Code Blocks, Basic Statements, and Loops

In this article, the latest of our C# in Simple Terms series, we're going to discuss how to control the flow of execution in a C# program. This means we will answer the question, "how does the code know what to do next?"