Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Sep 16, 2013 at 03:45 PM by Rabwin for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Rabwin · May 14, 2011 at 05:50 AM · arraystringmultidimarray

How to declare a multidimensional array of strings in c#?

I've tried some stuff like

public string[,] = new string[0,0];

and this line doesn't give me any errors in monodev or unity console, but it doesn't show up in the inspector, even if I place serialize field. I can still dynamically set strings with code, but can't give a predefined item in the inspector.
Is this supposed to happen?

Is there any way I can get into the inspector some kind of dynamic 2d array of type string?
This is exactly what I want, but this answer was for javascript.

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
3
Best Answer

Answer by Mortennobel · May 14, 2011 at 06:26 AM

You can create your own string array class and create an array of this:

using UnityEngine; using System.Collections;

[System.Serializable] public class MultidimensionalString { public string[] stringArray = new string[0];

 public string this[int index] {
     get {
         return stringArray[index];
     }

     set { 
         stringArray[index] = value; 
     }
 }

 public int Length {
     get {
         return stringArray.Length;
     }
 }

 public long LongLength {
     get {
         return stringArray.LongLength;
     }
 }

}

Usage:

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class ArrayTest : MonoBehaviour {

 public MultidimensionalString[] multidimensional = new MultidimensionalString[10];

 public void Start(){
     multidimensional[1].stringArray = new string[4];
     multidimensional[1][1] = "test";    
     Debug.Log(multidimensional[1][1]);
 }

}

This answer is based on the following answer:

http://answers.unity3d.com/questions/47049/visializing-a-multidimensional-array

An alternative is to create a custom editor for that gives access to a specific GameObject that contains either multidimensional array of arrays-of-arrays. Note that this is a less general approach that the MultidimensionalString.

http://unity3d.com/support/documentation/ScriptReference/Editor.html

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rabwin · May 14, 2011 at 06:53 AM 0
Share

Thanks very much, I like the first option it is quite perfect for my needs

avatar image Mortennobel · May 14, 2011 at 07:47 AM 0
Share

I added support for index-operator as well. Then it will work more like a real array.

avatar image Rabwin · May 14, 2011 at 08:52 AM 0
Share

Excellent, thanks for that!

avatar image Mortennobel · May 14, 2011 at 10:35 AM 0
Share

Updated again - I added a Length property ... like the array :-)

avatar image SAVOTW · Jul 27, 2012 at 01:21 PM 0
Share

Thanks :) This allowed me to create an array of a class to use to store 'Alien Race' data for my project that $$anonymous$$ono would not allow.

Show more comments
avatar image
0

Answer by grovalmitch · May 16, 2013 at 06:30 AM

here yo can see a simple multidimesional array c# sample code

http://net-informations.com/csprj/statements/cs-array.htm

groval

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image abhishek94095 · Jun 14, 2021 at 07:05 PM 0
Share

recently i tried to use multidimensional string array to store color of an object for that i have used this code

private string[,,] colorArray; colorArray[0,0, 0] = obj.color.ToString();

that thing works fine in visual studio and returns color as well

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

String array not working 1 Answer

How to convert a string to int array in Unity C# 1 Answer

convert string to byte array 3 Answers

Javascript - Calling a random String 2 Answers

Array of Array 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges