algorithmic modeling for Rhino
Hi
I am learning to script in c# in gh. I came across some difficulty - I cannot find any tutorials about creating classes in c#. I do not know any scripting besides processing, so I know that classes would work pretty much similiar. Can someone explain to me on some basic example how to create your own class?
There was some nice thing on aadrl2013/2014 but the website gone off.... :-(
Tags:
Er... hmm ...I would strongly suggest some proper reading (forget Internet: you can't learn programming that way):
The bible PlanA: C# In depth (Jon Skeet).
The bible PlanB: C# Step by step (John Sharp).
The bible PlanC: C# 5.0/6.0 (J/B Albahari) > my favorite
The reference: C# Language specs ECMA-334
The candidates:
C# Fundamentals (Nakov/Kolev & Co)
C# Head First (Stellman/Greene)
C# Language (Jones)
You can define a new class using the class keyword:
[private/protected/internal/public] [static/abstract/sealed] class MyClassName
{
// Class fields, constructors, properties and methods go here.
}
If you do not pick a scope specifier, then you'll get the default but I can never remember what the default is so I always specify a scope.
When a class is marked static, it may only contain static methods and fields. This means nobody ever constructs your class, all the functionality is available all the time via the class name, rather than via a class instance. Most classes are not static. A famous example of a class which is static is System.Math.
When a class is marked abstract, it means you cannot create instances of that class. Instead, the only way to use that class is to make another class which derives from the abstract class. I didn't include notation for class inheritance or interface implementations, you can read up on that online.
When a class is marked sealed, it means nobody can inherit from it. It's the proverbial end of the line.
Most often, what works well is simply:
public class MyClassName
{
// class content here...
}
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by