C
C#4h ago
brandon

c# hw help

i need to complete steps 6, 7, 8 but i am pretty lost about how to do it
12 Replies
brandon
brandonOP4h ago
i did step 6 but it looks weird for (int careerIndex = 0; careerIndex < Careers.Length; careerIndex++) { Console.Write($"{careerIndex + 1}. {Careers[careerIndex]} ("); for (int attributeIndex = 0; attributeIndex < PrimaryAttributesShort.Length; attributeIndex++) { Console.Write($"{PrimaryAttributesShort[attributeIndex]}: {CareerTemplates[careerIndex][attributeIndex]}"); if (attributeIndex < PrimaryAttributesShort.Length - 1) Console.Write(", "); } Console.WriteLine(")"); }
Mango
Mango4h ago
Have you tried it? Does it do what its expected to do, or is there an error?
brandon
brandonOP4h ago
it works but i just used youtube to type it out and i dont even understand it myself. its not stuff weve gone over in class that looks familiar does that look like an inefficient way or advanced way or doing it
Mango
Mango4h ago
Im on my phone, sorry its hard to read here. I'm not sure I fully grasp what your professor wants but on my phone quickly skimming it looks fine
brandon
brandonOP4h ago
its okay your help is much appreciated it as is
Mango
Mango4h ago
It looks like a beginner way I suppose. Theres ways you can restructure the code to reduce the amount of loops you do for things but thats far beyond what your current lessons are I'll be back in 10-15min on a computer if nobody else pops in here and I'll rewrite that code with some comments on whats going on
brandon
brandonOP4h ago
i just dont understand what the primaryattribute short. length -1 is and what this code even says okay i really appreciate it thank you os much
Angius
Angius4h ago
.Length gives you the number of elements. So, for an array that contains 3 elements, like [81, 45, 129] it will give you 3 Arrays (and lists, and other collections) in C# are, however, 0-indexed Meaning the indexes here are
0 81
1 45
2 129
0 81
1 45
2 129
array.Length - 1 is the way to get the last index of the array In your specific example, what the code does, is it checks if the current index is less than the max index, and if so, it prints a comma So that the output is 81, 45, 129 and not 81, 45, 129,
Mango
Mango3h ago
Is it just that bit or other bits?
Mango
Mango3h ago
BlazeBin - lrzutlxdpkuz
A tool for sharing your source code with the world!
Mango
Mango3h ago
I've added some comments to this code
brandon
brandonOP2h ago
omg this is so detailed and helpful thank you oh i see ok thank you i was confused by it

Did you find this page helpful?