C# Multidimensional Array (Im completely lost)

Posts 18 of 8 · Page 1 of 1
C# Multidimensional Array (Im completely lost)
I am having a hard time doing this task. I have never really working with multidimensional arrays so any information on how to go about this or some code, anything would be appreciated.

Task:
for(int i -0, i<x; i++
step 1: inout 1 name 1 object 1 action word
step 2: store in 3darray [i,i,i]array
Note: Must be stored in the same position in the array [anme,object,actionword]
}

any help would be appreciated
Code:
var myDictionary = new Dictionary<string, Dictionary<object, string>>();
            for (int i = 0; i < myDictionary.Count; i++)
            {
                var element = myDictionary.ElementAt(i);
                var name = element.Key;
                var valueOfElement = element.Value;
                for (int e = 0; e < valueOfElement.Count; e++)
                {
                    var obj = valueOfElement.ElementAt(e).Key;
                    var actionWord = valueOfElement.ElementAt(e).Value;
                }
            }
to get actionword, for example -var actionword = myDictionary[name][object];
Quote Originally Posted by NPDevTeam View Post
to get actionword, for example -var actionword = myDictionary[name][object];
I needed to store all 3 in this Multidimensional array[name,object,acitonW] heres the concept in my mind, Let me know if thats what you did.

Code:
                for(int i=0; i<=totalWords; i++)
                {
                    Console.WriteLine("Please enter name#" + i + ":");
                    Console.WriteLine("Please enter verb#" + i + ":");
                    Console.WriteLine("Please enter action#" + i + ":");
                    //This is the hard part tho... I need to store those 3 different string inputs into an multidimensional array 
                    array[weord,verb.action] //Has to be stored in the same index                }
Quote Originally Posted by iAmRishi View Post
I needed to store all 3 in this Multidimensional array[name,object,acitonW] heres the concept in my mind, Let me know if thats what you did.

Code:
                for(int i=0; i<=totalWords; i++)
                {
                    Console.WriteLine("Please enter name#" + i + ":");
                    Console.WriteLine("Please enter verb#" + i + ":");
                    Console.WriteLine("Please enter action#" + i + ":");
                    //This is the hard part tho... I need to store those 3 different string inputs into an multidimensional array 
                    array[weord,verb.action] //Has to be stored in the same index                }
You don't need multi-dim array.
You can use new Tuple array for this.

Code:
(string name, string verb, object action)[] myTupleArray = new (string, string, object)[totalWords];

... for ...
myTupleArray[i] = (userInput.Name, userInput.Verb, userInput.Action);
... /for ...
TIP: Don't forget to download System.ValueTuple from nuget
Quote Originally Posted by Zaczero View Post


You don't need multi-dim array.
You can use new Tuple array for this.

Code:
(string name, string verb, object action)[] myTupleArray = new (string, string, object)[totalWords];

... for ...
myTupleArray[i] = (userInput.Name, userInput.Verb, userInput.Action);
... /for ...
TIP: Don't forget to download System.ValueTuple from nuget
Not to necro, but wanted to say thanks for this. I've been fiddling with swapping arrays, datasets, and sqlite connectors for a work project for about 2 weeks and I think this may have just solved my problem.
Quote Originally Posted by Zaczero View Post


You don't need multi-dim array.
You can use new Tuple array for this.

Code:
(string name, string verb, object action)[] myTupleArray = new (string, string, object)[totalWords];

... for ...
myTupleArray[i] = (userInput.Name, userInput.Verb, userInput.Action);
... /for ...
TIP: Don't forget to download System.ValueTuple from nuget
In before this gets marked as incorrect by incompetent teachers <:
Yeah a teacher might mark that off, but in a work place if it works and doesn't take ages it's a good solution (barring any security issues, but it's all offline). I'm self taught and my C# is terrible (it's not my job to code I do it to save time) so it works for me lol.
Thank you all for coming to my support. THis is now solved and here is what I did.

Code:
string[,] Arra = new string[3, 9];
for (int a = 0; a <= (totalWords - 1); a++)
{
Console.WriteLine("Please enter name#" + (a + 1) + ":");
Arra[0, a] = Console.ReadLine();
}
Posts 18 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?