473,506 Members | 16,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Next problem, this time arrayoriented

H
Ok, now this newbie is dealing with arrays.
I have some questions on this. I thought I'd use the built in Array class,
since it contains all I need for sorting, copying etc. arrays. Now I'm
wondering if this is so clever. As I've understood it, one good thing with
the Array class is that it is partly dynamical, since there is a function
for adding elements to the array, although it thtows an exception...
But what I'm having the real problems with is to access the values in the
created array ...
For Example

class class1
{
private String string1;
public String string2;

public String GetString1() { return string1;}
}

// and in the Main()
Array myArray = Array.CreateInstance(typeof(class1), 50); // No
errors/problem this far ....
// Here I'd like to get/set value of String1, HOW ?
//--------------------------------------------------------------------------
--
// The way I can think of is like this
class1 myVar = new class1();
myVar.string2 = "blablabla";
myArray.SetValue(myVar, 5);
//--------------------------------------------------------------------------
--
// But how do I make a function call in class1 in the array ? I can't figure
out how to it with ex. GetValue() ...

2. If the above is solved, how do I sort the Array using Sort() ?
If I'd for example like to sort it alphabetically on string1 ...
TIA (again)



Nov 15 '05 #1
1 1135
Hi,
[inline]

"H" <no*********************@hotmail.com> wrote in message
news:0U********************@newsc.telia.net...
Ok, now this newbie is dealing with arrays.
I have some questions on this. I thought I'd use the built in Array class,
since it contains all I need for sorting, copying etc. arrays. Now I'm
wondering if this is so clever. As I've understood it, one good thing with
the Array class is that it is partly dynamical, since there is a function
for adding elements to the array, although it thtows an exception...
You cannot add elements to an Array once it's instantiated.
If you want to remove & add elements dynamical use e.g. ArrayList.
But what I'm having the real problems with is to access the values in the
created array ...
For Example

class class1
{
private String string1;
public String string2;

public String GetString1() { return string1;}
A property would be perfect for this:
public string String1
{
get { return string1; }
set { string1 = value; } // remove if you want it readonly
}
}

// and in the Main()
Array myArray = Array.CreateInstance(typeof(class1), 50); // No
errors/problem this far ....
When declaring arrays, the Array class is used implicit and the syntax is
easier:
class1[] myArray = new class1[50];
myArray[0] = new class1();
myArray[0].String1 = "klk";
...
Console.WriteLine ( myArray[0].String1 );

Sort is a static method in the Array class, you can use it like:
Array.Sort( myArray );
//note that sort only works when the objects in the array implement
IComparable
HTH
greetings
//-------------------------------------------------------------------------- --
// The way I can think of is like this
class1 myVar = new class1();
myVar.string2 = "blablabla";
myArray.SetValue(myVar, 5);
//-------------------------------------------------------------------------- --
// But how do I make a function call in class1 in the array ? I can't figure out how to it with ex. GetValue() ...

2. If the above is solved, how do I sort the Array using Sort() ?
If I'd for example like to sort it alphabetically on string1 ...
TIA (again)



Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5173
by: jason | last post by:
Is there a way to avoid On Error Resume Next for: cnn.Open strCon SQL = "EXEC Customer @txtEmail='" & email_address & "'" set rs = cnn.execute(SQL) 'On error resume next rs("email_address")...
8
1904
by: Alex | last post by:
ACC 2000 I am having problems working out how to adding up minutes? Example:using short time Date Timestart Timend Minutes 25-jan-04 15:00 16:00 60
13
1478
by: andreas | last post by:
Hi, I want to do some calculation like ( t1 and t2 are known) for i = t1 to t2 for j = t1 to t2 ..... ..... for p = t1 to t2 for q = t1 to t2
7
21898
by: fniles | last post by:
In VB 6.0 in the error trapping, we can do "resume next" to continue on the next code. How can we do that in .NET with "Try", "Catch","End Try" ? Thanks
1
1944
by: foothills bhc | last post by:
I have a problem with verifying content of controls on a form before closing the form or moving to the next form "record" (i.e., when moving to the next row of my form's record source). HERE'S THE...
4
2589
by: keri | last post by:
Hello again, While I try and solve the calender issue I also have another problem. I have a form & table (appointments) where the user records appointments in the future. The fields include...
1
2191
by: Keychain | last post by:
I'm stuck on what seems like should be a relatively easy problem. I'm creating a simple scheduler. From a form consisting of seven checkboxes (one for each day of the week) the user selects the...
8
10802
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
0
2688
by: solargovind | last post by:
Hello, I have few problem with Dlookup condition. I need to retrieve next record or previous record based on certain condition. The conditions are set in in the combo box. Here, I am trying to...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.