Re: Array of Objects Initialization problem C#.
- From: "Daniel" <DanielV@xxxxxxxxxxxxxxxx>
- Date: Sun, 21 Jan 2007 11:53:45 -0000
Hi
Very hard to understand your problem as i presume english is not your first
language. i think you are saying that you are initialising an array to 1000
because you know what you are filling it with will always be less than that.
But you want to add to the array as you need without prior initialisation?
if so....you have two choices, an array list or a List<>.
with list you do this
List<myObject> myList = new List();
then to add an object you do this
myList.Add(myObject);
with an ArrayList it is very simple as well. So look up arraylists and lists
and you will solve your issue.
P.S. C# allows for using unmanaged (unsafe) code where you can use pointers
in more of a c++ manner. But you don't need this anyway.
<sk.rasheedfarhan@xxxxxxxxx> wrote in message
news:1169379879.296575.97110@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi ,
Here I am new user to C#, my problem is I have to use dynamic Array of
objects. But I heard C# don't support ptrs (using managed code C#
support).
In short i initialized objects of 1000 and I am using is upto 10 or
less. Because of that I find 990 reset of them as un initialized
objects, when I extract the information from the Object it will throw
an exception also and I feel unnecessarily I am wasting of memory.
So I need dynamic allocation of the objects so can any body give me
some samples or suggestion then it will be very help full
Brief discussion of my problem I declare array of Object in 1ST Step
and Initialized in 2nd Step. What I am doing in My 3rd Step I don't
know.
When I am parsing array of Objects I find so many un initialized
objects( as per my step2 means 1000). but actually I storing the data
in object RulesProperties is very less in step3 i.e m_icount.
public class RuleXMLParser
{
Step1: RuleXMLParser [] RulesProperties;
public RuleXMLParser()
{
//Do some initialization
}
public void InitializeRules(XmlNodeList RuleNodes)
{
Step2: RulesProperties = new RuleXMLParser[1000];
for(int i = 1; i < RuleNodes.Count; i++)
{
for(int j = i+1; j< RuleNodes.Count -1; j++)
{
CompareRuleNodes(RuleNodes[i],RuleNodes[j]); }
}
}
}
private void CompareRuleNodes(XmlNode RuleNodes1,XmlNode RuleNodes2)
{
Step3: RulesProperties[m_icount] = new RuleXMLParser();
}
.
- References:
- Array of Objects Initialization problem C#.
- From: sk . rasheedfarhan
- Array of Objects Initialization problem C#.
- Prev by Date: Array of Objects Initialization problem C#.
- Next by Date: Re: Array of Objects Initialization problem C#.
- Previous by thread: Array of Objects Initialization problem C#.
- Next by thread: Re: Array of Objects Initialization problem C#.
- Index(es):
Relevant Pages
|