Command line arguments in c# -
i pretty new c# . got problem command line arguments. want make use of third cmd line argument , write it. have specified path of file want write , other stuffs. question here can access command line arguments(for eg; args[3]) user defined functions? how tat? below code.
public class nodes { public bool isvisited; public string parent; public string[] neighbour; public int nodevalue; public nodes(string[] arr, int nodevalue) { this.neighbour = new string[arr.length]; (int x = 0; x < arr.length; x++) this.neighbour[x] = arr[x];//hi...works?? this.isvisited = false; this.nodevalue = nodevalue; } } public class dfs { static list<string> traversedlist = new list<string>(); static list<string> parentlist = new list<string>(); static bufferblock<object> buffer = new bufferblock<object>(); static bufferblock<object> buffer1 = new bufferblock<object>(); static bufferblock<object> buffer3 = new bufferblock<object>(); static bufferblock<object> buffer2 = new bufferblock<object>(); public static void main(string[] args) { int n = 100; int m = n * 4; int p = n * 16; stopwatch stopwatch = new stopwatch(); stopwatch.start(); list<string> global_list = new list<string>(); streamreader file = new streamreader(args[2]); string text = file.readtoend(); string[] lines = text.split('\n'); string[][] array1 = new string[lines.length][]; nodes[] dfsnodes = new nodes[lines.length]; (int = 0; < lines.length; i++) { lines[i] = lines[i].trim(); string[] words = lines[i].split(' '); array1[i] = new string[words.length]; dfsnodes[i] = new nodes(words, i); (int j = 0; j < words.length; j++) { array1[i][j] = words[j]; } } streamwriter sr = new streamwriter(args[4]); int startnode = int.parse(args[3]); if (args[1].equals("a1")) { console.writeline("algo 0"); buffer.post(1); dfs(dfsnodes, startnode, "root"); } else if (args[1].equals("a2")) { console.writeline("algo 1"); buffer1.post(1); dfs1(dfsnodes, startnode, "root",sr); } else if (args[1].equals("a3")) { buffer3.post(1); list<string> visitedtlist = new list<string>(); console.writeline("algo 2"); dfs2(dfsnodes, startnode, "root", visitedtlist,sr); } stopwatch.stop(); console.writeline(stopwatch.elapsed); console.readline(); } public static void dfs(nodes[] node, int value, string parent,streamwriter sr1) { int id = (int)buffer.receive(); sr1=new streamwriter(arg console.writeline("node:" + value + " parent:" + parent + " id:" + id); sr1.write("node:" + value + " parent:" + parent + " id:" + id); id++; traversedlist.add(value.tostring()); buffer.post(id); (int z = 1; z < node[value].neighbour.length; z++) { if (!traversedlist.contains(node[value].neighbour[z])) { dfs(node, int.parse(node[value].neighbour[z]), value.tostring(),sr1); } } return; } public static void dfs1(nodes[] node, int value, string parent, streamwriter sr) { int id = (int)buffer1.receive(); sr.write("node:" + value + " parent:" + parent + " id:" + id); node[value].isvisited = true; node[value].parent = parent; id++; buffer1.post(id); (int z = 1; z < node[value].neighbour.length; z++) { buffer2.post(node[int.parse(node[value].neighbour[z])]); if (!isvisited()) { dfs1(node, int.parse(node[value].neighbour[z]), value.tostring(),sr); } } return; } public static void dfs2(nodes[] node, int value, string parent, list<string> visitedtlist, streamwriter sr) { int id = (int)buffer3.receive(); sr.write("node:" + value + " parent:" + parent + " id:" + id); id++; visitedtlist.add(value.tostring()); buffer3.post(id); (int z = 1; z < node[value].neighbour.length; z++) { buffer2.post(node[int.parse(node[value].neighbour[z])]); if (!visitedtlist.contains(node[value].neighbour[z])) dfs2(node, int.parse(node[value].neighbour[z]), value.tostring(), visitedtlist,sr); } return; } public static bool isvisited() { nodes node = (nodes)buffer2.receive(); return node.isvisited; } } so thing want write output of each dfs file specified command line argument. can have access args in dfs, dfs1 methods??? thank you.
you either keep static field hold it, or use environment.getcommandlineargs().
Comments
Post a Comment