Re: args.length doesnt work!
else{
Application.Run(new Form());
Console.WriteLine("Started at Form with arguments...");
}
?
Re: args.length doesnt work!
Is there more code to this program? When I run it I get a "'System.Array' does not contain a definition for length" message.
But if I capitalize "Length" in args.Length I don't get this message.
Also, you're missing a semi-colon in the code above after "Application.Run(new Form1())" but that's not likely your problem.
Re: args.length doesnt work!
If this is a WinForms app then you may not be able to run it from a command prompt and get output to the Console. I don't know that for a fact as I haven't checked, but it's possible.
Re: args.length doesnt work!
Hi!
try this :source from: http://msdn.microsoft.com/library/de...rstutorial.asp
Code:
// cmdline1.cs
// arguments: A B C
using System;
public class CommandLine
{
public static void Main(string[] args)
{
// The Length property is used to obtain the length of the array.
// Notice that Length is a read-only property:
Console.WriteLine("Number of command line parameters = {0}",
args.Length);
for(int i = 0; i < args.Length; i++)
{
Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
}
}
}
The proper syntax to get the length of any given one-dimensional array is to use the Length propery of a System.Array object. By entering the length property in lowercase will result in a exception as described in a few posts back. Compile this and run it in console with arguments. It should work.
t sami
Re: args.length doesnt work!
As said, the form shows, so the argument of length and Length is not valid in this case. There are no compile time errors occur in his code. The code posted was just a typo.
Re: args.length doesnt work!
The code that Sami Antero posted is no doubt from a Console application, as opposed to a WinForms app as your's is.
Re: args.length doesnt work!
Are you sure, mine is made through WinApp? I can make it a Console App, just referred to System.Windows.Forms namespace to be able to access what Techno needs. By running this also, we can see the console window.
Techno, also you can set the arguments at Project Properties->Configuration Properties->Command Line Arguments... Just to make you not run the code at command line. Of course, this assumes you have the studio. But if you are in the command line, (hat's off) you'll be fine.
Re: args.length doesnt work!
Yup! I've waken up. It is true that the example I gave was a bit offline with the topic. Sorry. Well at least that got me started.
I tried to replicate Tenchnos problem but got the whole thing working ok. While in vs2003 the args printout in the output window ok (defined in the project properties) and console with args works ok.
Techno states that the question of lowercase and uppercase is not valid in this question. How did you get the application to compiled if you are referring to System.Arrays length property?
Re: args.length doesnt work!
I did not. He said, it works ok, so I assume the code is just typed barely from his mind (not copy pasted from the working editor). But you are too keen to spot .length with .Length.... Well of course, Techno didn't have his original code .length because (as he said) it runs Ok, there's a logical bug. Not -- a syntax error.
BTW, your code is good for manipulating the args. Just a reference of how to doing this stuff. Nice. Also, the link you've given is broken. The (:) should be removed as the last letter of the link. Please edit. Thanks.
Re: args.length doesnt work!
True, the problem mus be a logical one. The code as I imagine it must be has no flaws in it. The reason I emphasised on the Length argument was ewomacks post on 'System.Array does not ....' post earlier so sorry about it (I end up excusing everything, should have stayed in bed.. :eek2: ). It would be nice to know though if techno got this sorted.
ps the link ok now, thanks for the advice
Re: args.length doesnt work!
wow...tyvm guys!
I am very sorry - the .length was a typo as i was typing in the code! :) it's .Length...
I will try the other suggestions.....however i remember doing this stuff in another project at work but forgotten how it was done, im sure it was the same way I written it here...
I will update you with these resolutions.. :)
ty!
Re: args.length doesnt work!
Are you compiling this as an exe or a winexe?
Re: args.length doesnt work!
Re: args.length doesnt work!
try compiling to exe then the output to the console should show up, and you'll still be able to display the Window when no args are applied.
Re: args.length doesnt work!