Howdy all hope everyone is having fun with there own projects! But i have come once again to be a pain in the ^**^.

I need to know an easy way of doing this -> as an example say:

I would like to some how use a MultiDarray in this way. or another way.

say i created something like this:

string[,] Blah = new string[,] { { "asda"", "now" }, { "tesr", "basdjh" } };

Now that's cool but i would like to add items to this array.
so that in the end i could do some like

How to add to this array once it's been defined or in the process of init?

string filenamestr;
string pathnaestr;

 filenamestr = blah.getvalue(i,1);
 pathnaestr = blah.getvault(i,2);

So what i mean is there anyway to create a method or store say multile values at given locations within that record(array).

Recommended Answers

All 4 Replies

Reading is easy, you just access it like you defined it:

// it's been a while for me, but try one of these
filenamestr = blah[0,0]; 
filenamestr = blah[0][0];

Changing the data is much harder. I *think* (but like I said, not sure) those values are not locked in, so you can say:

blah[0][0] = "new string";

If someone else can verify, or if you test it, that would be great.

The hard part is inserting new strings to grow the arrays, and deleteing strings to shrink the arrays. This can't be done because the definition fixes the dimensions of the arrays. You can get around this by using Lists or Array objects, which will definitely let you change any lengths you want, but makes the declaration and all around usage more complex.

PS: If you are just working with filenames and paths, you can stick with an array of strings and call System.IO.Path.GetDirectory(blah[0]); and System.IO.Path.GetFilename(blah[0]); to determine the path and filename.

Cheers Miki for quick response. You have hit the nail on the head. One an array has been defined it looks like what you said it's locked.

I wonder if there is away to construct a List<int><string><string> = new...

or some kind of class constructor...(get'n thinking now) say BlahDatalocations.Filename + BlahDatalocations.NewName + BlahDatalocations.IconLocationPath and this would return those parts from a....are I don't to be a easy way....gezzz it's been a long day....

This is what I currently doing

List<string> BlahStRhere = new list<string>();

say BlahStRhere[3] has a value of "x:\sadasd\asdsa\ && "f:\asdsd\sadsad\sadasd\ && d:\licon.ico" etc......

and this use a silly old :-
string argh = BlahStRhere.remove(blastrhere.indexof("&&")......

but instead would be goo to have Say BlahStRhere[1]. or something similar.

Why not use a List of objects that can contain anything you want?
Something like this perhaps:

namespace ConsoleApplication1
    public class Names //class with 2 strings in it
        public string Str1;
        public string Str2;

        public Names(){}

        //anything else here

    class Program
        static void Main(string[] args)
            List<Names> MyList = new List<Names>(); //make empty list
            //fill list with 10 Names objects called N
            //with index i appended to every name
            //never worry about indexing or expanding, just add!
            for (int i = 0; i < 10; i++)                
                Names N = new Names();
                N.Str1 = "abc" + i.ToString();
                N.Str2 = "def"+ i.ToString();
            // print list by indexing its elements
            for (int i = 0; i < MyList.Count; i++)
                    ("Element nr.{0} contains {1} and {2}.", i + 1, MyList[i].Str1, MyList[i].Str2);
            Console.ReadKey(); //keep console on screen in debug mode          
commented: Very Quick with the Solution i was thinking about.. +2

Nice...Cheers Very Much For Thatly...I new there was a reason why i Hadn't forgotten My Login Cred for DaniWed....Ha ha...

Thanks DDan and Miki for there very useful helpage....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.