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…

c# - ToCharArray equivalent for List<string> - Stack Overflow

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

1 Like

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.

1 Like

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

7 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.

4 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?

9 Likes

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

3 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();
3 Likes

Add me to the list of users who got confused here. It could have at least mentioned that we’d need to look up how to do Arrays etc.

7 Likes

Technically, and the way I understood the assignment, we are instructed to “Change a string to a list of chars”. A list of characters would be formatted as below and not as an array of characters. With that in mind, the following should have worked and didn’t. So not only is the lesson structured poorly, but in this case, the instructions were as well.

            string myTest = "Test";
            List<char> myTestSpelling = new List<char>();
            myTestSpelling.AddRange(myTest);

How do I open the terminal in the ‘Review’ exercise, to practise some code?

  string fede = "Valverde";
  char[] n = new char[8];
  char a;
  ramos_1 = Convert.ToString(ramos);
  Console.WriteLine(ramos_1);
         n = fede.ToCharArray();

for (int i =0; i <8; i++)
{
a=n[i];
Console.WriteLine(a);
}

1 Like

Wow…that was a bit much, CodeAcademy. Talk about being thrown into the deep end…

2 Likes

Hello CodeCademy users!

I’m practicing/doing some hw and I’m currently working on the exercise “Converts a boolean to a string”

I am not sure if my code is proper; I was hoping someone could chime in. The reason why I’m not sure/confident is NOT because I get an error BUT because the boolean variable converted into a String (true) is coming up on the terminal as “True” (Capital T). I thought if it was converted to a string it would show all in lowercase. Am I over thinking/looking too hard or is there a mistake on the code?

This is the code I wrote:

//convert from bool to string

bool userStates = true;
string conversion = Convert.ToString(userStates);

//testing the results
Console.WriteLine(conversion);

Again, I do not get an error but it’s returning “True” instead of “true”.

1 Like

It isn’t a mistake in the code. Apparently, that’s the way C# does the conversion.

In the documentation, you can see an example showing similar output.

Related thread,

2 Likes

Thank you so much for those references and that screenshot! It looks like I’m going to be using “.equals” moving forward when in doubt. Cheers!