FAQ: Data Types and Variables - Review

This community-built FAQ covers the “Review” exercise from the lesson "Data Types and Variables ".

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I tried to be a good student and do the extra homework from that page. One of them:

  • Changes a string to a list of chars

So apparently that can’t be done implicitly or explicitly and one must use function to do so. ToCharArray, I think, should be the function but “it does not exist in the current context”.

Let me know if I am wrong and I am missing something,

1 Like

Please post a link to this exercise. Thanks.

Here it is:

https://www.codecademy.com/courses/learn-c-sharp/lessons/csharp-data-types-variables/exercises/review-data-types-variables-csharp

There is something here about converting char to string…

https://stackoverflow.com/questions/27085218/tochararray-equivalent-for-liststring

Can’t be much help as this is my first foray into C#.

Can you post the code that you tried?

Implicit conversion:
string myTest = “Test”;
char myTestSpelling = myTest;

Explicit conversion:
string myTest = “Test”;
char myTestSpelling = (char)myTest

Using the Convert function:
string myTest = “Test”;
char myTestSpelling = Convert.ToChar(myTest);

Using the online-found function
char myTestSpelling = myTest.ToCharArray();

None of these work.

This should have worked:

string myTest = "Test";
char[] myTestSpelling = myTest.ToCharArray();

Did you get an error message with the ToCharArray()? If not, try this below it:

foreach(char myChar in myTestSpelling) {
    Console.WriteLine(myChar);
}

Should output:
T
e
s
t

5 Likes

Uh, this time around it did work. I probably had a typo, how embarrassing.

I must say, even for an extra homework, this one was particularly difficult.
Thanks for the help.

2 Likes

Am I missing something here? The tutorial went from converting data types in the given sheet to suddenly requiring for loops and “lists” which haven’t been covered yet?

2 Likes

The structure of this particular CodeAcademy class is very poor. It’s about a that lesson I started considering learning elsewhere.

2 Likes

I agree this “csharp-data-types-variables” lesson has been written quite poorly.
We were never taught how to deal with Lists, and yet they expect from us to do that (“Convert a string to a list of characters”).

Thank you @shintenpu for posting a solution. This worked perfectly!

char[] myTestSpelling = myTest.ToCharArray();
1 Like