|
Whenever I declare an array I have to say how big it is... i.e. [7]...
Now, what if I don't know how big it needs to be...? How would I do that?
/\ |_ E X E GG
|
|
|
|
|
Some examples:
int[] i;
i=new int[]{0,1,2,3,4,5};
i=GetArray();
A good tutorial on arrays in C#[^]
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Thanks for the link.
/\ |_ E X E GG
|
|
|
|
|
here is an example.
using System.Collections;
...
array = new ArrayList();
int[] myArray = array.ToArray(typeof(int));
this example will turn the ArrayList object into an array of int objects, you can change the type of array returned by changing the parameter of the ToArray method.
Another Post by NnamdiOnyeyiri l Website
|
|
|
|
|
|
There are two different ways of interpreting what you write:
1) You know the size of the array at runtime, but not at compile time.
public int [] CreateArray(int size)
{
int [] array = new int[size];
return array;
} The second method is when you don't know ahead of time how many elements you'll need. This typically happens when you are dealing with data being input by the user.
public int[] CreateArray()
{
string input = "";
ArrayList alist = new ArrayList();
Console.WriteLine("Enter a number then press enter, to quit just press enter");
while("" != (input = Console.ReadLine()) )
{
int i;
try
{
i = int.Parse(input);
}
catch
{
Console.WriteLine("\"{0}\" is not a valid input number, try again",
input);
continue;
}
alist.Add(i);
}
return (int[]) alist.ToArray(typeof(int));
} All code has not been compiled so errors my exist
James
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
The second one is what I wanted, thanks.
/\ |_ E X E GG
|
|
|
|
|
I must say once again, Thanks. This nice example you set up for my question really helped me out today.
Good Man.
/\ |_ E X E GG
|
|
|
|
|
I need to embedd a treeview inside each row of a listview. and be able to have row sizes only per row to accomadate the listview.
Does anyone know of any articles on this?
thanks,
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
There's two articles here on CP on exactly this subject, look them up under C# Controls.
|
|
|
|
|
I got below error message when I try to run my application on a Win2000 system with .netframework 1.1 installed.
Application has generated an exception that could not be handled.
No debugger found.
Registered JIT debugger is not available.
An attempt to launch a JIT debugger with the following command resulted in an error code of 0x2(2) . Please check computer settings.
cordbg.exe ! a 0x724.
Pls help me. Thanks a lot for your replying.
Thanks.
coby
|
|
|
|
|
The VS errlook.exe util says this about error 0x724:
Incompatible version of the serializing package.
This seems to hint at problems with either the Object or XMl serializers - check if there's been any changes with the type you are using between framework versions.
Also, try wrapping the code in you Main class in a try{} catch{} group so you can get more meaningful error messages. For example:
[STAThread]
static void Main(string[] args)
{
try
{
Form1 main = new Form1();
main.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), ex.Message);
}
}
|
|
|
|
|
Thank you very much for the response. I did add the code in the project. And then I got below message.
System.Security.SecurityException: Request for the permission of type
System.Data.SqlClient.SqlClientPermission,System.Data, Version= 1.0.5000.0, Culture= neutral,
PublickeyToken=b77a5c561934e089 failed.
at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet grantedSet,PermissionSet deniedSet, CodeAccessPermission demand,PermissinToken permToken,
.....
It seems that I can't get the permission to access Sql server. Could you pls tell me how to resolve this issue?
Thanks.
coby
|
|
|
|
|
When you add a visible control to a form in VS.NET, such as a textbox, the Properties box shows several properties with sub-properties. For example, the Font, Location, and Size properties have a [+] next to them which you can click to reveal sub-properties.
I'm now creating a custom control myself for which I want add a property with sub-properties. How is that done? Is there an example I can look at somewhere?
I really appreciate your help,
Alvaro
If you want to get to the top, prepare to kiss a lot of bottom. -- despair.com
|
|
|
|
|
Bending the PropertyGrid to Your Will[^] by Tony Allowatt. It's an excellent article, well worth reading.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I spent some time reading the article but unfortunately it didn't have what I needed with respect to custom controls. However, thanks to one of the "Other Article" links at the bottom of that article, I ran into the solution from one[^] of the comments made on it.
Thanks for pointing me in the right direction.
Regards,
Alvaro
If you want to get to the top, prepare to kiss a lot of bottom. -- despair.com
|
|
|
|
|
Alvaro Mendez wrote:
I'm now creating a custom control myself for which I want add a property with sub-properties. How is that done? Is there an example I can look at somewhere?
I really appreciate your help,
This is done with attributes, here is an example where using the same Category attribute's name will cause the Color property and the String property to be grouped under Options (note each property has it's own Description ). Hope this helps.
internal class Properties
{
[Category("Options"),
Description("The color of the header on main form at top.")]
public Color Color
{
get{return _color;}
set{_color = value;}
}
[Category("Options"),
Description("Some string used in the app.")]]
public String String
{
get{return _s;}
set{_s = value;}
}
private Color _color;
private String _s;
}
-Nick Parker
|
|
|
|
|
I don't think so. You didn't understand the question
And I don't know the answer!
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Meisi wrote:
You didn't understand the question
Ummm, yes I did.
Meisi wrote:
And I don't know the answer!
Read my previous post again.
-Nick Parker
|
|
|
|
|
Meisi wrote:
You didn't understand the question
Nick Parker wrote:
Ummm, yes I did.
Why didn't you answer it, then...;)
|
|
|
|
|
Arjan Einbu wrote:
Why didn't you answer it, then.
Oppps, my mistake. Guess I need some
-Nick Parker
|
|
|
|
|
Nick Parker wrote:
Ummm, yes I did.
Actually no Nick. I was referring to Sub-Properties not Categories. Take a look at the Font property. It's already under the "Appearance" category, but it also has its own set of properties.
Thanks anyway, and here's[^] the solution in case you're interested.
Regards,
Alvaro
If you want to get to the top, prepare to kiss a lot of bottom. -- despair.com
|
|
|
|
|
Alvaro Mendez wrote:
Actually no Nick. I was referring to Sub-Properties not Categories. Take a look at the Font property. It's already under the "Appearance" category, but it also has its own set of properties.
Again, opps, sorry I did mis-understand what you initially meant.
-Nick Parker
|
|
|
|
|
Nick Parker wrote:
I did mis-understand
hehe! you see? you didn't corrctly understand the question!
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Meisi wrote:
hehe! you see? you didn't corrctly understand the question!
That's ok, I do now.
-Nick Parker
|
|
|
|