internal static void Main(string[] args) => new Thread(() => Request_Response()) { Name = "Executor" }.Start();
internal static void Request_Response()
{
string[] args = new string[3];
args[0] = "foo";
args[1] = "bar";
foreach (string str in args)
{
if (!string.IsNullOrEmpty(str))
Debug.WriteLine($"Before declaring args new string[] {str}");
}
args = new string[] { "foobar" };
foreach (string str in args)
{
Debug.WriteLine($"After declaring args as new string[] {str}");
}
}
Lol. Thanks. I have looked at your code. I sort of understand the logic but could not utilize the debug console effectively to figure out the flow. I will look closely at your spoiler for further instruction on C# programming.If you want to understand why your code is not working. You should; and I implore you to run this code and tell me after you have read the Output window. Why foo and bar are no longer in the string array when foobar is initialised?
What seems obvious when you then look at this sample code code? This code is no different to the mistake you just made.
Once you work that out, then look at your own code and then tell us what the problem is?
I've just had a bottle of wine, and I can still see your issue.C#:internal static void Main(string[] args) => new Thread(() => Request_Response()) { Name = "Executor" }.Start(); internal static void Request_Response() { string[] args = new string[3]; args[0] = "foo"; args[1] = "bar"; foreach (string str in args) { if (!string.IsNullOrEmpty(str)) Debug.WriteLine($"Before declaring args new string[] {str}"); } args = new string[] { "foobar" }; foreach (string str in args) { Debug.WriteLine($"After declaring args as new string[] {str}"); } }
![]()
What do you advise? Please find the attached. Same algorithm was called (directly from cmd) and the algorithm appears to have executed correctly though not sequentially (Here, It took all the parameters at once). I want to be able to utilize ```args.Length>1``` so that other parameters can be considered from the console.Yes. Re-read that post that you just quoted.
Add this using directive to the top of your code file.I sort of understand the logic but could not utilize the debug console effectively to figure out the flow.
using System.Diagnostics;
args
right after you execute the line that says:args = new String[] { Console.ReadLine() };
args
array? How does that compare to your expected "--input-image" on line 39 of post #11 or line 56 of post #15?Console.ReadLine()
to interactively get input from the user?args
of a Main()
method refers to the the command line arguments passed to the program. This means that these are the parameters passed to the program when you run the program in the CMD or PowerShell console. You are going to confuse other people who read (and use) your code when they see that your Main()
takes command line arguments, but completely ignores them and instead interactively gets input from the user, but expects the user to type in the input as if they were command line parameters.Hello, Thanks again for the assistance so far. Can you advise how I can parse this line ``` args = new String[] { Console.ReadLine() };``` such that the parameters supplied can be split to array elements. args[0], args[1], args[2] etcYes. Re-read that post that you just quoted.
I really appreciate this. The program is to be deployed as a Console Application. I am meant to improve the current implementation of the present algorithm. The task is to ease up the program flow and make it more user friendly without tampering with the core libraries. I introduced a variable to be able to assess the value of args.length and I noticed the value is always 1 regardless of the different parameters provided. Do you think I can correct this with the <args.String.Split (' ').ToArray();> function?Now as something completely meta to your current code: Why are you usingConsole.ReadLine()
to interactively get input from the user?
By convention the variable namedargs
of aMain()
method refers to the the command line arguments passed to the program. This means that these are the parameters passed to the program when you run the program in the CMD or PowerShell console. You are going to confuse other people who read (and use) your code when they see that yourMain()
takes command line arguments, but completely ignores them and instead interactively gets input from the user, but expects the user to type in the input as if they were command line parameters.
No.Do you think I can correct this with the <args.String.Split (' ').ToArray();>
Ok. Thanks: I will get to it and update shortly.No.
You're creating the same problem. In order to understand what you're doing wrong, you need to go back to post #17, and test the code I gave you. Why? Because the mistake you are making, I've already wrote out. Now if you had used and tested the code in a new application, and actually debugged it, you would have found what you are doing wrong. I even have the debug write back to the output window in VS for you to identify the output provided by the method. Put a break point on Request_Response and step through the example I gave you and try to identify why foo and bar don't print after args is reinitialised. I and other have already pointed out what you're doing wrong, and I've also provided at least three different links, which if you had read; it would be abundantly clear what the problem is. So read back through the topic from post 13 onwards.