Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Streams and Data Processing Reading Data Encoding

help pls

Challenge Task 1 of 2

Create a new byte array variable named mysteryMessage and initialize it with the following values: 89, 0, 97, 0, 121, 0, 33, 0. Important: In each task of this code challenge, the code you write should be added to the code from the previous task. Restart Preview Get Help Check Work CodeChallenge.cs

1 ā€‹

CodeChallenge.cs

3 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points

Well ok, let's start from the beginning.

we need to initialize an array of type byte. Ok, so we know that we need a variable and it tells us it must be called mysteryMessage. Let's create a variable with that name.

var mysteryMessage

We know it must equal something. We use the equal sign to initiate the variable. Meaning give it live, or in this case give it a value. The question gives us the value. . We know the values, we know it's a byte array meaing we must declare the type of array as byte and use the [] to indicate it's an array. We then give it values that are given to use in the question by putting them inside the {}.

var mysteryMessage = new byte[] { 89, 0, 97, 0, 121, 0, 33, 0 };

Now we have a variable with the proper name, which is initialized with the = sign, and it's an array of type byte. We did that with the byte[]. Than we put the values it told us to use in the array.

Once we do that, The next question says the following.

Create a new variable named messageContents. Great we know how to create a variable and we know it needs to be initialized. (var to declare the variable initialize it with the =)

var messageContents =

Ok, the next part says, we need to initialize it with the value of UnicodeEncoding.Unicode.GetString. Ok well I can tell by the .'s (periods) in the name, we are calling a method.

var messageContents = UnicodeEncoding.Unicode.GetString()

Ok, I now have the method. But I am not actually assigning it a value yet. I am calling this Unicode method on nothing. But the questions tells me to call it on my previous variable. So let me put that in the ().

QUESTION and use the UnicodeEncoding.Unicode.GetString method to initialize it with the contents of mysteryMessage.

var messageContents = UnicodeEncoding.Unicode.GetString(mysteryMessage);

Now I created a variable named messageContents. I initialized it using the = sign. I called the method in the directions and I passed it a variable. The variable I created in step 1. Which means that the method is going to get called against my already created variable, which will encode it and save that value as messageContents.

Does this help? Let me know and I can try to approach it differently if you need.

Hendrik Heim
Hendrik Heim
1,012 Points

As an appendix to the comment above me:

byte[] mysteryMessage = {89,0,97,0,121,0,33,0}; 

is the short version of initializing a byte array with these values.

thank's

I just wanted to say that the way you explained the steps made it a lot easier to break down a task into smaller steps. It's a well written and very useful post in many ways.

HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
21,058 Points

byte[] mysteryMessage = {89,0,97,0,121,0,33,0};

var messageContents=UnicodeEncoding.Unicode.GetString(mysteryMessage);

HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
21,058 Points

byte[] mysteryMessage = {89,0,97,0,121,0,33,0}; it works