Just starting, looking for some pointers

Rei Ayanami

New member
Joined
Nov 15, 2022
Messages
1
Programming Experience
Beginner
Hey, I recently wanted to get back into programming, but my only experience was simple Java and python from my school classes, the farthest we really went was covering the basics such as syntax, but I'd like some pointers or good resources to learn C# as it's the language I'm really interested in as I'm getting back into Unity. I'll take any advice from anyone willing to help no matter how simple the advice or pointers seem, anything helps :D
 
In general, C# code is called "code". Don't call them "scripts". Except in Unity. There C# code is called "scripts".

I highly suggest learning the language first and focusing on just console applications. Once you have firm grasp on the the language, the branch out into learning some GUI, web, or game programming framework. It's easier to climb up just one learning curve instead of trying to climb up two or more learning curves simultaneously.
 
If you're looking for pointers, you've come to the wrong language :ROFLMAO:

Joking aside, a list of "tips on coding C#" is unlikely to be really helpful to you. Perhaps take a pluralsight course on your topic of interest, have a bash at writing something and come ask us if you get stuck. One tip I will impart though:

Learning C# is like learning French (or Spanish, whatever..) - you think in English, you don't think in French. Do your thinking in English, not C#.

Just as when you learn French, you know what you want to say in English ("I like the red balloon") then tweak it to be how a French person woudl say it ("I like the balloon red"), then translate the words ("J'aime le ballon rouge"), then speak the French

When you learn C# you have an aim in mind; an algorithm of what your program will do. Wite the program in English first, using comments. After you've done that, translate the comments to C#. If you launch straight into coding, with no plan of what you need to code, you'll get lost and forget what you're doing, and then write a load of bug-ridden junk

Example:

Your task is "add up the numbers at the end of every line in this text file, but only if the line starts with an A"

You write the algorithm first, in English:

C#:
//read the file into an array, one line per array element
//have a varable to track the sum
//loop over every line in the array
  //does the line start with an A?
    //yes it does
    //extract the numeric digits after the last comma
    //convert the numeric string to a number
  //add it to the sum
//do the next line

Now, you fill C# in under them, and you leave them there so you have a nicely commented program that tells you what each line does; being able to read a line and just know its purpose is a skill that you acquire as you become fluent in C#, you aren't there yet

C#:
//read the file into an array, one line per array element
var lines = File.ReadAllLines("c:\path\to\file.txt");

//have a varable to track the sum
var sum = 0;

//loop over every line in the array
foreach(string line in lines){

  //does the line start with an A?
  if(line.StartsWith("A")){
    //yes it does
    //extract the numeric digits after the last comma
    var bits = line.Split(',');
    var numstring = bits.Last();

    //convert the numeric string to a number
    var num = Convert.ToInt32(numstring);

    //add it to the sum
    sum+= num;
  }
//do the next line (loop around)
}

You can get fancy with it later:
C#:
var sum = File.ReadAllLines("C:\path\to\file.txt").Where(l => l.StartsWith("A")).Sum(l => int.Parse(l.Split(',')[^1]));

That last line of code is perhaps the *last* thing you should be writing as a newbie; chock full of code with no explanation and needs a fairly high degree to C# fluency to read it. A fellow developer who is LINQ aware would pick it up and go "oh right, that's self explanatory" - but that's the "think in C#" level.. Think in english, lay it out in english, then translate

*or your native spoken language
 
Last edited:
Side note, Unity will teach you all manner of filthy coding habits that are totally alien to the rest of the C# universe. I'd definitely start with some other aspect first
 

Latest posts

Back
Top Bottom