Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C# Stuck understanding Array?

MRR

New Coder
What is the following code doing?

string result = new string (new char[])
{
'Profile_unknown'
});

Can you explain what the following code is and what it is actually doing? line by line Please

9.png

the next one as well

new string(new char[]
{
'tdata'
}
 
What is the following code

string result = new string (new char[])
{
'Profile_unknown'
});
Generating compiler errors is what it's doing. It's illegal in C# to put more than one character between ' '. It's also not permitted to declare an array without a size ir initializer
 
What is the following code doing?

string result = new string (new char[])
{
'Profile_unknown'
});

Can you explain what the following code is and what it is actually doing? line by line Please


the next one as well

new string(new char[]
{
'tdata'
}

Think of it this way.

C#:
string username = "ABCDEFG";
char[] userNameArray = new char[] {'A','B','C','D','E','F','G'};

//Look at the username almost like an array of chars (characters).
//Now, display both the username and the char array...what do you get?
Console.WriteLine($"The string of username = {username}");
Console.WriteLine();
Console.WriteLine("And the value of the userNameArray is:");
userNameArray.Dump();
Console.WriteLine("Which printed out is:");
Console.WriteLine(userNameArray);
/*
    You can reference a specific index of the string, which is a single char.
    You can't have a whole line of letters make up one letter :)

    Example - if I want to pick out the single letter 'D' above alone, I can look for that index of the string...which is a single character.
*/
Console.WriteLine();
Console.WriteLine($"Getting the letter {username[3]} here...");

Output:
1687322882984.png
 

New Threads

Buy us a coffee!

Back
Top Bottom