|
Why cant i do this? The value of "args" will be of similar format to the value i assigned to it. Im getting a "Index was outside the bounds of the array" error
static void Main(string[] args)
{
args[0] = "FrGbWOfvwO0=";
}
|
|
|
|
|
I guess the args is not initialized with any length of you don't start your application with any arguments. Why do you want to add values to the args array inside your code anyway?
|
|
|
|
|
Because it would be pointless ? The args collection is passed in, and exists only inside this method, why would you have any desire to change it ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
There is no element in the array args if you don't run the program with a command-line parameter. Therefore, args[0] does not exist. 0 is out of range.
|
|
|
|
|
In a recursive function for traversing a tree nodes , I want to invoke a function for the last child of a parent node( including all its grandchilds ). I have not found a technique for finding that node in the recursive function .
Any help ?
Thanks in advance.
|
|
|
|
|
List<TreeNode> nodeList = new List<TreeNode>();
private List<TreeNode> GetChildNodes(TreeNode treeNode)
{
foreach (TreeNode oNode in treeNode.Nodes)
{
nodeList.Add(oNode);
if (oNode.Nodes.Count > 0)
{
GetChildNodes(oNode);
}
else {
// this is the last node
}
}
return nodeList;
}
This would give you list of nodes in order as they would appear in expanded tree view.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
modified on Friday, October 23, 2009 6:39 AM
|
|
|
|
|
How to find the last grandchild of a parent node. All nodes have just one last grandchild.
in the following example node "node1_child3_child3" is the last grandchild of node1. Then how can I recognize that node in the recursive function ? What technique can I use ?
----node1
node1_child1
node1_child2
node1_child2_child1
node1_child2_child2
node1_child3
node1_child3_child1
node1_child3_child2
node1_child3_child3
modified on Friday, October 23, 2009 6:53 AM
|
|
|
|
|
If you need just the last node, change the return type of the method to treenode and use following code:
nodeList.Add(treeNode);
if (treeNode.Nodes.Count > 0) {
treeNode = GetChildNodes(treeNode.Nodes[treeNode.Nodes.Count - 1]);
}
return treeNode;
If you need complete heirarchy, you the following:
nodeList.Add(treeNode);
if (treeNode.Nodes.Count > 0) {
GetChildNodes(treeNode.Nodes[treeNode.Nodes.Count - 1]);
}
return nodeList;
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
I need to find the node while traversing the tree in the recursive function.
|
|
|
|
|
Isn't that recursion? GetChildNodes calling itself?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
yes but it gives me no way to identify the last grandchild of a node .
|
|
|
|
|
I used an addressing system for a similar problem(Drawing the tree)
here your address's woud be
0.0.0
0.1.0
0.2.0
0.2.1
0.2.2
0.3.0==node1_child3 Base node
0.3.1
0.3.2
0.3.3
**Would be 1.0.0... I think the answer is then obvious.
this pattern can then be applied to any depth of child...
|
|
|
|
|
Thanks for the reply. But I still don't get the approach ? can you elaborate please . The last grandchild here is 0.3.3.
How the traversing function would be then ?
|
|
|
|
|
here is an approximation since I don't know your exact structure:
<pre>
class address
{
list<int> token;
}
list<address> addresses = Tree.MapAddress();
int generation =0;
for(int i=0;i < addresses.Count-1;i++)
{
if(addresses[i+1].token[generation] > addresses[i].token[generation])
{ Console.Writeline("Your function result Here");} }
}
</pre>
Now I had some wonky recursion like I would need to skip children(closed leaf) and step into/out of children so you can navigate (almost as fast) using the address and recursion... but it takes a LOT of code. this is the smallest patch I can think of for your situation.
also you can change the generation by swapping out the generation number so if you wanted the line between great grand children and grand children switch 0->1, and voila.
modified on Friday, October 23, 2009 2:01 PM
|
|
|
|
|
ely_bob wrote: int generation =0;
for(int i=0;i < addresses.Count-1;i++)
{
if(addresses[i+1].token[generation] > addresses[i].token[generation])
{ Console.Writeline("Your function result Here");} }
}
What happend to the "generation" variable ? It is set to 0 and remains the same. Are you sure it is right ?
|
|
|
|
|
Yup.
That is a function stub, plop out that code and make a function with it:
myfunction(int generation){
for(int i=0;i < addresses.Count-1;i++)
{
if(addresses[i+1].token[generation] >addresses[i].token[generation])
{ Console.Writeline("Your function result Here");}
}
}}
just in case you want to reuse that code for say.. color coding your decendants.. you could use generation as the switch value so that your generations are all displayed in different colors... for example.
basically i just did it that way to show: that number can be set as a variable so you can get more mileage out of your code.
|
|
|
|
|
Hi all,
I am making a web application project. When the web application is run, the xml file will be always generated in a directory(app_data folder). The new xml file will overwrite the old one. I try to run with 2 browsers at once and one browser is successful and another one gets error and need to be refresh.
It is because the xml file is written by one application. So that I need to check the file status first when want to write. How to check the file status?Please include the code as it will very helpful for me. Thanks.
Regards,
Dedy
|
|
|
|
|
We have an ASP.NET forum.
The System.IO.File class probably does what you want. However, it sounds like what you're doing is stupid. Use a database to support multiple users, not an XML file
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Only way to check this is to try open the file. If you are using File.Open , one of the overload takes in FileShare as a parameter. That will allow muliple access. Although, not sure about what will happen when you simultaneously write something in the file from two sources.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
d@nish wrote: Although, not sure about what will happen when you simultaneously write something in the file from two sources.
The correct term is 'meltdown'. Well, it's 'race condition', but I think 'meltdown' might better illustrate the end result.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
OK. Thanks.
But I don't think OP would be using this since it is an XML and .Net does provide specific classes for that.
Btw, I never seem to understand your timezone.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
That's probably because I come on at 6 am, and it's 9 pm now.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Dear Friends,
I have one dll which is having all functionality for selected application.
now i want to create another dll which access that dll with some selected functionality and create one single dll, but when i use that single dll it giving error regarding the dependency.
can it possible to restrict user to access only the selected functionality dll instead of using the dll for all functionality. so that user can use that dll instead of other dll.
Thanks and regards
Sasmi
|
|
|
|
|
You can Trap that. lets say in the main DLL , there are Configuration function that you dont want your users to use. What you need to do is check the user rights before accesing the DLL. put some if statements based on the credentials
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi all,
I have created a new invisible form creating a new class with Main Run as an entry point and I haven't got any problems. My real problem is that I need that this program runs constantly and for this reason I have created a while(true) loop. This solution provided all my needs, but the cpu consumption rises to 50%, and for this reason is invalid. Any idea how can I fix it?. The solution "Windows Service" is not valid because these are started before logon and these have not the
Permissions of the Domain.
Thanks!
|
|
|
|