using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5 {
    class Program {
        enum _objID_1 {
            Name = "Lorem Ipsum"
        }

        static void Main(string[] args) {
            int ChosenDataID = 1;
            Console.WriteLine(_objID_ + ChosenDataID + _["Name"]);     // How about "Lorem Ipsum"? || Well, how about "no"?
        }
    }
}

Code is technically self-explaining.

@edit - I thought "enum" was represenative of "array" from PHP. But "array" does in exist in C# as well, so actual question would be, how to do it now with arrays.

Recommended Answers

All 5 Replies

You'll probably want to look at Dictionary<>. This ia basically a collection that is indexed by a key that can be pretty much any type and returns a value which also can be any type.

Would have worked. But Dictionary<> is limited to ID (key) and value (string). AND, this doesn't answer the question, I know enum, array and Dictionary<>, but I need to be able make array automatically, for example:

string[] user_*_array = new string[100];

for (int i = 0; i < 100; i++) {
    user_+i+_array[theidis] = "This array is + i +.";
}

Console.Write("The ID of user 67 is" + user_55_array["theidis"]);   // This array is 55.

Code written incorrectly. But it only made to give you idea of what I'm actually asking.

Would have worked. But Dictionary<> is limited to ID (key) and value (string)

Key and value can be anything you want.

Try this:

Dictionary<int, Dictionary<string, string>> user_array = new Dictionary<int, Dictionary<string, string>>();

for (int i = 0; i < 100; i++)
{
    user_array.Add(i, new Dictionary<string, string>() { { "theidis", string.Format("This array is {0}", i) }});
}

Console.Write(user_array[55]["theidis"]);

So I translate

var lining = File.ReadAllLines(@"C:\file.txt");

for (int i = 0; 0 < 1025; i++) {
    lining[i] = "Array: " + i * 2;
}
File.WriteAllLines(@"C:\file.txt", lining);

To:

var lining = File.ReadAllLines(@"C:\file.txt");

Dictionary<int, Dictionary<string, string>> lining = new Dictionary<int, Dictionary<string, string>>();

for (int i = 0; 0 < 1025; i++) {
    lining.Add(i, new Dictionary<string, int>() { {
            lining, string.Format(i * 2)
        }
    });
}

File.WriteAllLines(@"C:\file.txt", lining);

So I tried analyse your script and, maybe learn from it? Yea. Maybe. I failed horribly xD why is this so hilarious! :D

Going back to your original post I think you want something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
    class Program
    {
        public static Dictionary<int, Dictionary<string, string>> _objIDs = new Dictionary<int, Dictionary<string,string>>
        {
            {1,new Dictionary<string,string>
                        {
                            { "Name","Lorem Ipsum" }
                        }
            }
        };
        static void Main(string[] args)
        {
            int ChosenDataID = 1;
            Console.WriteLine(_objIDs[ChosenDataID]["Name"]); // How about "Lorem Ipsum"? || Well, how about "no"?
        }
    }
}
Be a part of the DaniWeb community

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