C
C#8mo ago
Ryan

❔ Amateur game dev LF help with some basic C#/programming knowledge

Hey all. Just for reference my knowledge in programming is limited to a university intro course for C++ back in 2021 and currently taking the Unity tutorial series on Unity's website for making basic games. My goal is to use Unity along with my digital asset creation skills to make a video game for my university thesis project. My major is in studio arts with a concentration in animation. Because programming takes some time to get used to and become fluent with I wanted to familiarize before my pre-thesis semester. I'll be posting some very fundamental questions here that I'm still trying to wrap my head around. Once I understand them I'll never need to ask again. I find difficulty with many of the tutorials that explain programming as if I've been programming for several years. This skill is very abstract so while it is difficult I just need to learn and understand a little differently. Question 1: what is the function of a "library" such as using System.Collections; or using UnityEngine;? Is it a reference tag kind of like the title or chapter in a cookbook, such that you couldn't cook without having read that first? Question 2: What is class? Why are there so many? is there a relationship between a library and class?
58 Replies
Aaron
Aaron8mo ago
there's a bit of terminology i should clear up real quick those things that come after using are namespaces, a single library can contain any number of namespaces
Ryan
Ryan8mo ago
I see
Aaron
Aaron8mo ago
they're just ways to categorize classes, so you dont have everything accessible at once if you dont need it otherwise you'd have several thousand classes all show up in your intellisense, which isnt fun, and they can all conflict with each other
Ryan
Ryan8mo ago
Does it affect file size, or does it just affect function of your program?
Aaron
Aaron8mo ago
it doesn't, they're just used by your IDE and the compiler to figure out what things you want accessible you dont even need to have the using if you didn't want to use the classes in them, things are accessible as UnityEngine.Vector3 for example
Ryan
Ryan8mo ago
so ignoring namespaces doesn't affect the program?
Aaron
Aaron8mo ago
it doesn't, they're purely a thing for our convenience
Ryan
Ryan8mo ago
Ok. So knowing them is cool but I can skip them and focus on the stuff beneath it
Aaron
Aaron8mo ago
IDEs will automatically add them nowadays anyway when you try to use something from a namespace you don't already have a using for
Ryan
Ryan8mo ago
Just wanted to be sure it wasn't an issue of needing to reference in anything and the program just not execute
Aaron
Aaron8mo ago
as for classes, they're a lot of things? their biggest job is being a container for data, and they usually have methods on them for reading or changing that data they contain
Ryan
Ryan8mo ago
Ok. That all leads me to a related question: I'm trying to understand the hierarchy of "code blocks" in a script. Can they be broken down into subsections that work similarly among all programs? Such as namespaces above containers above methods?
Aaron
Aaron8mo ago
if i understand the question, yeah, programs follow a pretty normal style
Ryan
Ryan8mo ago
Is there a picture you can share or something I should google to explain this visually?
Aaron
Aaron8mo ago
explain what visually, exactly
Ryan
Ryan8mo ago
Sort of like an organizational chart for a company You have your boss, your supervisors, your foremen, then your laborers for example (example of a construction crew)
Ryan
Ryan8mo ago
No description
Ryan
Ryan8mo ago
This comes to mind But if I'm wrong feel free to call me out
Aaron
Aaron8mo ago
well, i can do this Assembly (a project, essentially) - Namespaces - Classes - Methods - Fields - Properties (methods that look like fields) - Events - Structs - Methods - Fields - Properties - Events - Interfaces - Methods - Properties
Ryan
Ryan8mo ago
Yes! That's great Thank you
Aaron
Aaron8mo ago
classes and structs are (for the most part, they have one very big difference that isnt important at this point) the same thing
Ryan
Ryan8mo ago
Ok, stuff I'll probably learn soon. I'm doing the 8 hr microsoft tutorial a little bit every day. Very good stuff there as well.
Aaron
Aaron8mo ago
and interfaces are a different thing than those two that can help classes and structs say "i can do these things" i feel a bit bad since that kinda dumps a lot on you, but it at least shows that heirarchy
Ryan
Ryan8mo ago
So the namespaces are just there to say "hey, this is the kinda stuff we're using here", the classes, structs, and interfaces are the bigger picture items, and all the content inside those code blocks dictate how the program functions. No not at all, I may not have understood the hierarchy otherwise
Aaron
Aaron8mo ago
namespaces are just categories for "types", which is the name for classes, structs, and interfaces as a group
Ryan
Ryan8mo ago
General Structure of a C# Program - C#
Learn about the structure of a C# program by using a skeleton program that contains all the required elements for a program.
Ryan
Ryan8mo ago
I guess "skeleton" is the term I should be looking up as well or just structure
Aaron
Aaron8mo ago
yeah that shows the other "types" i omitted since they're not super important delegates and enums and it shows that namespaces can contain other namespaces, though you never really see that
Ryan
Ryan8mo ago
Ok. Last question for now as I've taken up a bit of your time here: what is the easiest way to understand what a container is If container is a broad term that can relate to a ton of different things, what's a few container examples that explains why it's a container? Like I understand that an array dictate the position in a list from 0 to whatever number Like a folder to me is a digital container
Aaron
Aaron8mo ago
well, when i said "container", i just meant literally, in the source code, thats where you put your logic and data, so it "contains" those things
Ryan
Ryan8mo ago
So does it function like a chapter title in a text book or does it allow things to execute as well? I'm sorry if this is all asked really Barney style, I've just been struggling this bad lol
Aaron
Aaron8mo ago
like if i have this
class Student
{
public string FirstName;
public string LastName;

public string GetFullName()
{
return FirstName + " " + LastName;
}
}
class Student
{
public string FirstName;
public string LastName;

public string GetFullName()
{
return FirstName + " " + LastName;
}
}
its a container for a first name and a last name, it stores those things inside itself
Ryan
Ryan8mo ago
For context, what does Get do? Is it for input?
Aaron
Aaron8mo ago
its just taking the first and last name and turning them into one string so i can do something like this
MODiX
MODiX8mo ago
Aaron
REPL Result: Success
class Student
{
public string FirstName;
public string LastName;

public string GetFullName()
{
return FirstName + " " + LastName;
}
}

Student myStudent = new Student();
myStudent.FirstName = "Aaron";
myStudent.LastName = "Robinson";

Console.WriteLine(myStudent.GetFullName());
class Student
{
public string FirstName;
public string LastName;

public string GetFullName()
{
return FirstName + " " + LastName;
}
}

Student myStudent = new Student();
myStudent.FirstName = "Aaron";
myStudent.LastName = "Robinson";

Console.WriteLine(myStudent.GetFullName());
Console Output
Aaron Robinson
Aaron Robinson
Compile: 588.862ms | Execution: 84.565ms | React with ❌ to remove this embed.
Aaron
Aaron8mo ago
that myStudent "instance" of the class will store its own first and last name, to be accessible later does that make any sense, lmao
Ryan
Ryan8mo ago
Oh just barely lol I'm trying to understand how all the lines relate, but that can be done another time
Aaron
Aaron8mo ago
I'm struggling to find a real world metaphor for what classes are and do
Ryan
Ryan8mo ago
I feel ya Most people who explain online don't do it so well, so don't feel bad. If it were simple then thousands of people wouldn't all be asking lmao.
Aaron
Aaron8mo ago
the GetFullName method and that last line aren't super important to what i'm trying to show there
Ryan
Ryan8mo ago
public string GetFullName() { return FirstName + " " + LastName; } These absolutely relate, correct?
Aaron
Aaron8mo ago
yes, thats one whole method
Ryan
Ryan8mo ago
Like the immediate code block written beneath the string is meant for that string alone, so long as the } ends the method line
Aaron
Aaron8mo ago
public isn't super important, but then string is the kind of data the method will give back, and GetFullName is the name of the method, with the inside of the () being an (empty) list of the extra data it needs to do its job { is where the method's body starts, where it can actually do work, and } ends that body
Ryan
Ryan8mo ago
I agree
Aaron
Aaron8mo ago
its not optional, thats a requirement by the language to have you are required to show where classes and methods start and end with braces or it will yell at you kekw
Ryan
Ryan8mo ago
Right, such that a sentence ends with a period. or a line ends with ; return FirstName + " " + LastName; The return part I'm not sure what that's fore
Aaron
Aaron8mo ago
thats how you give back data (here a string) to whatever asked for it
Ryan
Ryan8mo ago
Console.WriteLine(myStudent.GetFullName()); makes the text values of public string FirstName and public string LastName show in text As Console means "text" essentially
Aaron
Aaron8mo ago
the FirstName + " " + Lastname is just taking the first name, putting a space after it, then putting the last name after that
Ryan
Ryan8mo ago
and WriteLine means "display it in text"
Aaron
Aaron8mo ago
to write a new line of text to the consoile, yeah
Ryan
Ryan8mo ago
I agree I'm just not sure the purpose of return
Aaron
Aaron8mo ago
methods can contain multiple lines that do different things, so it needs to know when you want to give back the final result whatever called GetFullName wants some data back, here it wants the full name return is saying "i have the full name you wanted, so now i will give that data back to you and stop working"
Ryan
Ryan8mo ago
Ok so after the data is called, in this case to be presented in text-based form, the program is concluded after it displays Otherwise it would just print infinitely? Or probably error lol
Aaron
Aaron8mo ago
yeah, the repl is a bit weird since it lets you put code anywhere on the top level but in a normal program, if a method doesn't return any data (it has void as its return type), you don't need return it will just end after the last line
Ryan
Ryan8mo ago
Hmm I seee Thank you so much for taking the time to explain this, I have zero programmer friends and have struggled using tutorials and sites like quora or w3schools to explain this stuff for the minds of 5 year olds Once I recognize the patterns and organization better it will all click, but I feel useless doing tutorials and practicing all while pretending I know how this stuff works or relates
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.