473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Does the .NET framework keep an internal List/Hashtable/Collection of all my Lists that I can loop over?

Hello,

I have a static class with several hundred private static List<>. Does the
..NET framework keep an internal List/Hashtable/Collection of all my Lists
that I can loop over? If so, please show the syntax or docs reference, if
it's there I am unable to find it.

TIA,

M
Sep 25 '07 #1
2 1101
Mark S. kirjoitti:
Hello,

I have a static class with several hundred private static List<>. Does the
.NET framework keep an internal List/Hashtable/Collection of all my Lists
that I can loop over? If so, please show the syntax or docs reference, if
it's there I am unable to find it.

TIA,

M

I guess you can use Reflection

using System.Reflection;
...
MyClass myInstance = new MyClass();
// Get the type of MyClass.
Type myType = typeof(MyClass);
try {
FieldInfo[] myFields = myType.GetFields(BindingFlags.Static |
BindingFlags.NonPublic);
for(int i = 0; i < myFields.Length; i++) {
// Check that myFields[i].Name suites
Object obj = myFields[i].GetValue(myInstance);
}
} catch (Exception ex) {
Console.WriteLine("Exception {0}", ex);
}

--
Arto Viitanen
Sep 25 '07 #2
Thank you for your suggestion. Below is an brief representation of the code
in question. Using your sample code I'm able to get it to generate:
Name: myList1
Name: myList2

However, I don't have the skills (even going to "Google University" this
afternoon), as this is the first time I've coded reflection code, to get it
to show something like:
myList1 ID: 123
myList2 ID: null or not in list

Would you be so kind as extend your example?

using System;
using System.Reflection;

public class TestIDClass
{
public volatile string ID;
}

public static class TestListClass
{
public static List<TestIDClassmyList1 = new List<TestIDClass>();
public static List<TestIDClassmyList2 = new List<TestIDClass>();
}

static class test
{
static void Main(string[] args)
{
TestIDClass myIDClass = new TestIDClass();
myIDClass.ID = "123";
TestListClass.myList1.Add(myIDClass);

Type myType = typeof(TestListClass);
try
{
FieldInfo[] myFields = myType.GetFields(BindingFlags.Static |
BindingFlags.Public);
for (int i = 0; i < myFields.Length; i++)
{
Console.WriteLine("Name: " + myFields[i].Name);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception {0}", ex);
}
}
}
Sep 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard...
18
by: JezB | last post by:
How can I loop thru a hashtable changing the Value of each entry ? Whatever I try I always seem to get the error about modifying the collection within the loop.
8
by: Arnaud Debaene | last post by:
Hello all, One area where the .Net framework 1.1 is really poor is Collections : We've got very few choice concerning the containers and their characteristics (for example, ArrayList, Queue and...
10
by: Mart | last post by:
What class does everyone out there use if they want to store a set of values efficiently? In java I use a HashSet, but there is no equivalent in C#. Even worse, the lowest level interface to...
8
by: source | last post by:
a function that would: return the 5th element from the end in a singly linked list of integers, in one pass, and then provide a set of test cases against that function. Can we do this in CSharp?...
38
by: ssg31415926 | last post by:
I need to compare two string arrays defined as string such that the two arrays are equal if the contents of the two are the same, where order doesn't matter and every element must be unique. ...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
15
by: Macca | last post by:
Hi, My app needs to potentially store a large number of custom objects and be able to iterate through them quickly. I was wondering which data structure would be the most efficient to do this,a...
3
by: =?Utf-8?B?QWJlUg==?= | last post by:
I am trying to look for change in an instanciated object that contains a generic list<>. I first get an int value of objA.GetHashCode(). I add a few objects to the list<collection in objA I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.