0

I know classes aren't used much in VB.NET. I have looked everywhere trying to understand how classes work in C#, it's as if I needed an analogy for each lesson I have learned, I have logic and loops down, but when it comes to classes, my brain just freezes up. I have tried books and online tutorials. I for the life of me cannot understand how classes work and how they are called between linking. Its almost as hard for me to learn pointers in C.

Does anyone know a good resource or site that will break it down evenly even for the non-gifted tech?

3
  • 5
    I know classes aren't used much in VB.NET. ehh? Most things in VB.NET are classes. Commented Oct 24, 2011 at 12:35
  • 6
    Of course classes are used in VB.NET - whatever makes you think they're not? Commented Oct 24, 2011 at 12:35
  • 1
    So you're basically asking to explain what classes are and how they work in C#? Commented Oct 24, 2011 at 12:42

2 Answers 2

3

There are plenty of resources all over the internet with this information, no doubt, but if I may point out what is noted in the C# Language Specification (with further linkage):

1.6 Classes and objects

Classes are the most fundamental of C#’s types. A class is a data structure that combines state (fields) and actions (methods and other function members) in a single unit. A class provides a definition for dynamically created instances of the class, also known as objects. Classes support inheritance and polymorphism, mechanisms whereby derived classes can extend and specialize base classes.

New classes are created using class declarations. A class declaration starts with a header that specifies the attributes and modifiers of the class, the name of the class, the base class (if given), and the interfaces implemented by the class. The header is followed by the class body, which consists of a list of member declarations written between the delimiters { and }.

The following is a declaration of a simple class named Point:

public class Point { public int x, y; public Point(int x, int y) { this.x = x; this.y = y; } } 

Instances of classes are created using the new operator, which allocates memory for a new instance, invokes a constructor to initialize the instance, and returns a reference to the instance. The following statements create two Point objects and store references to those objects in two variables:

Point p1 = new Point(0, 0); Point p2 = new Point(10, 20); 

The memory occupied by an object is automatically reclaimed when the object is no longer in use. It is neither necessary nor possible to explicitly deallocate objects in C#.

This information is the bottom line, and should be coldly understood - the links to important peripheral (but fundamental) aspects go some way to provide further reading. Enjoy!

Sign up to request clarification or add additional context in comments.

Comments

0

A class:

public class Program { public void Run() { Console.WriteLine("Hello world"); } } 

running it:

var program = new Program(); program.Run(); 

Comments