473,763 Members | 4,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String Array Object to an ArrayList

Hi,

I've begun converting an ASP site over to .NET and I'm a novice at both the
new platform as well as C#.

I have a COM+ object that returns a string array when it is called. The
size of the array can vary depending on the parameters passed.

What I need to do is loop through the returned array and if applicable write
the array element to the screen.

I'd like to know if an ArrayList is the best way to go or is there something
else in C# I should use. I'm not adding, deleting or appending anything to
the returned array.

Secondly, what would be the syntax for this?

What I have so far is the declaration:
ComLogicEngine. ComPlusLogic oConfig = new
ComLogicEngine. ComPlusLogic();

And the call to the COM+ object:
oConfig.Execute ("blah", "blah", "blah");
Thank you for your help,

JJ
Nov 16 '05 #1
8 13947
Jeff Johnson <je**********@h otmail.com> wrote:
I've begun converting an ASP site over to .NET and I'm a novice at both the
new platform as well as C#.

I have a COM+ object that returns a string array when it is called. The
size of the array can vary depending on the parameters passed.

What I need to do is loop through the returned array and if applicable write
the array element to the screen.

I'd like to know if an ArrayList is the best way to go or is there something
else in C# I should use. I'm not adding, deleting or appending anything to
the returned array.


Then why do you need to do anything with it? Why not just iterate
through it, eg with:

foreach (string x in myStringArray)
{
....
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
The Array part syntax:

string[] myArray;

myArray = new String[] { "test1", "Test2", "TEST3" };

foreach (string s in myArray) {

Console.WriteLi ne(s);

}

"Jeff Johnson" <je**********@h otmail.com> wrote in message
news:e3******** ******@tk2msftn gp13.phx.gbl...
Hi,

I've begun converting an ASP site over to .NET and I'm a novice at both the
new platform as well as C#.

I have a COM+ object that returns a string array when it is called. The
size of the array can vary depending on the parameters passed.

What I need to do is loop through the returned array and if applicable write
the array element to the screen.

I'd like to know if an ArrayList is the best way to go or is there something
else in C# I should use. I'm not adding, deleting or appending anything to
the returned array.

Secondly, what would be the syntax for this?

What I have so far is the declaration:
ComLogicEngine. ComPlusLogic oConfig = new
ComLogicEngine. ComPlusLogic();

And the call to the COM+ object:
oConfig.Execute ("blah", "blah", "blah");
Thank you for your help,

JJ

Nov 16 '05 #3
I tried using the syntax below, substituting my call to the COM+ object
where you entered "test1"... and I received an error. I have been
successful in binding it to a DataGrid. I'm not sure if that helps in
describing the state of object when it is returned.

Do you have any other ideas on how I could approach this?

JJ

"Mythran" <ki********@hot mail.com> wrote in message
news:uL******** ******@TK2MSFTN GP09.phx.gbl...
The Array part syntax:

string[] myArray;

myArray = new String[] { "test1", "Test2", "TEST3" };

foreach (string s in myArray) {

Console.WriteLi ne(s);

}

"Jeff Johnson" <je**********@h otmail.com> wrote in message
news:e3******** ******@tk2msftn gp13.phx.gbl...
Hi,

I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#.

I have a COM+ object that returns a string array when it is called. The
size of the array can vary depending on the parameters passed.

What I need to do is loop through the returned array and if applicable write the array element to the screen.

I'd like to know if an ArrayList is the best way to go or is there something else in C# I should use. I'm not adding, deleting or appending anything to the returned array.

Secondly, what would be the syntax for this?

What I have so far is the declaration:
ComLogicEngine. ComPlusLogic oConfig = new
ComLogicEngine. ComPlusLogic();

And the call to the COM+ object:
oConfig.Execute ("blah", "blah", "blah");
Thank you for your help,

JJ


Nov 16 '05 #4
Hrm....

string[] myArray = <call to com to receive array>;

foreach yadda yadda yadda...

Mythran

"Jeff Johnson" <je**********@h otmail.com> wrote in message
news:en******** ******@TK2MSFTN GP12.phx.gbl...
I tried using the syntax below, substituting my call to the COM+ object
where you entered "test1"... and I received an error. I have been
successful in binding it to a DataGrid. I'm not sure if that helps in
describing the state of object when it is returned.

Do you have any other ideas on how I could approach this?

JJ

"Mythran" <ki********@hot mail.com> wrote in message
news:uL******** ******@TK2MSFTN GP09.phx.gbl...
The Array part syntax:

string[] myArray;

myArray = new String[] { "test1", "Test2", "TEST3" };

foreach (string s in myArray) {

Console.WriteLi ne(s);

}

"Jeff Johnson" <je**********@h otmail.com> wrote in message
news:e3******** ******@tk2msftn gp13.phx.gbl...
Hi,

I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#.

I have a COM+ object that returns a string array when it is called. The
size of the array can vary depending on the parameters passed.

What I need to do is loop through the returned array and if applicable write the array element to the screen.

I'd like to know if an ArrayList is the best way to go or is there something else in C# I should use. I'm not adding, deleting or appending anything to the returned array.

Secondly, what would be the syntax for this?

What I have so far is the declaration:
ComLogicEngine. ComPlusLogic oConfig = new
ComLogicEngine. ComPlusLogic();

And the call to the COM+ object:
oConfig.Execute ("blah", "blah", "blah");
Thank you for your help,

JJ



Nov 16 '05 #5
No dice.

I get an "Cannot implicity convert type 'object' to 'string[]'" error when I
try that.

"Mythran" <ki********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hrm....

string[] myArray = <call to com to receive array>;

foreach yadda yadda yadda...

Mythran

"Jeff Johnson" <je**********@h otmail.com> wrote in message
news:en******** ******@TK2MSFTN GP12.phx.gbl...
I tried using the syntax below, substituting my call to the COM+ object
where you entered "test1"... and I received an error. I have been
successful in binding it to a DataGrid. I'm not sure if that helps in
describing the state of object when it is returned.

Do you have any other ideas on how I could approach this?

JJ

"Mythran" <ki********@hot mail.com> wrote in message
news:uL******** ******@TK2MSFTN GP09.phx.gbl...
The Array part syntax:

string[] myArray;

myArray = new String[] { "test1", "Test2", "TEST3" };

foreach (string s in myArray) {

Console.WriteLi ne(s);

}

"Jeff Johnson" <je**********@h otmail.com> wrote in message
news:e3******** ******@tk2msftn gp13.phx.gbl...
> Hi,
>
> I've begun converting an ASP site over to .NET and I'm a novice at both
the
> new platform as well as C#.
>
> I have a COM+ object that returns a string array when it is called.
The > size of the array can vary depending on the parameters passed.
>
> What I need to do is loop through the returned array and if

applicable write
> the array element to the screen.
>
> I'd like to know if an ArrayList is the best way to go or is there

something
> else in C# I should use. I'm not adding, deleting or appending
anything to
> the returned array.
>
> Secondly, what would be the syntax for this?
>
> What I have so far is the declaration:
> ComLogicEngine. ComPlusLogic oConfig = new
> ComLogicEngine. ComPlusLogic();
>
> And the call to the COM+ object:
> oConfig.Execute ("blah", "blah", "blah");
>
>
> Thank you for your help,
>
> JJ
>
>



Nov 16 '05 #6
Jeff Johnson <je**********@h otmail.com> wrote:
No dice.

I get an "Cannot implicity convert type 'object' to 'string[]'" error when I
try that.


So cast it to a string[] - assuming you're absolutely sure that it
*does* return a string array.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
I believe that it does return a string array.

Maybe to help explain things, I'm trying to convert this code from
ASP/VBScript to C#:

arrData = comPlusObject.E xecute("a", "b", "c")

for(i=0 to ubound(arrData) )
response.write( arrData(i))
next

In ASP, that call returns an array that is easily parsed. I'm not sure why
what has been suggested doesn't work. I've found that I can bind what's
returned from the call to the COM+ object to a datagrid without any issues.

JJ
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Jeff Johnson <je**********@h otmail.com> wrote:
No dice.

I get an "Cannot implicity convert type 'object' to 'string[]'" error when I try that.


So cast it to a string[] - assuming you're absolutely sure that it
*does* return a string array.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #8
I've been in a similar situation. I solved the problem by implementing a
method that first casts the returned array and then converts the
returned array to a String array.

Using the method o2s (you might find a better name) below you can do
something like:

string[] arrData = o2s(comPlusObje ct.Execute("a", "b", "c"));
// Then just use the String array
Console.WriteLi ne( arrData[0] );

The method has been designed to access Lotus Notes String item values
using the Domino COM interface (domlib.tlb).

The number of String elements returned will be equal to the number of
elements returned by the called COM method.

This could probably also have been done by a simple System.Array.Co pyTo,
but in order to avoid null pointer exceptions I wanted to set the first
String element to an empty string if the COM method returns null.

I'm using the code below in a console application. Depending on your
implementation you may have to remove the static attribute.

static string[] o2s ( Object obj){
// cast the System.Object to a System.Array
Array objArray = (Array) obj;

// create a string array of same size
string[] strArray = new string[objArray.Length];

// loop through the System.Array and populate
// the String Array
for (int i = 0; i < objArray.Length ; i++) {
if (objArray.GetVa lue(i) == null)
// In order to avoid null pointer exceptions
// we will return an empty string in the first
// element if the first element retruned by
// the call to the COM method is null.
strArray[i] = "";
else
strArray[i] = (string)objArra y.GetValue(i).T oString();
}
return strArray;
}
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

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

Similar topics

1
2311
by: psmith | last post by:
I am getting data back from a COM object. In the debugger, I get back an object as follows: result -> system.array -> {length=102} string | |--> ="company 1" string |--> = "company 2" string etc.
9
23703
by: Davids | last post by:
is it true that I cannot dynamically add an item to an array? Eg public char = {"a","b"}; char.Add("newitem"); Do I really have to switch to ArrayList to do this?
1
1151
by: Ken Varn | last post by:
I have a C++ function in which I want to be able to new String Array object passed into it, but I can't get the syntax. Can someone help? Example: void MyFunc(String *MyString __gc) { // I want to be able to do a new on MyString so that the caller gets the newed object.
0
915
by: john conwell | last post by:
Any idea or code example how i can marshal a SWStringArray to a .Net string array or ArrayList?
5
17112
by: RGood | last post by:
Hi, I have a TextBox that contains the following text. User1;User2;User3; ... and so on. Each string is seperated by ";". What is the best way to retreive the strings and place into a string array or ArrayList since i would not know how many strings are in the TextBox?
4
2819
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so that I can preform complicated operations against this data. The returned record count in these operations is always variable. 1. I have been using an arraylist.add function to handle non-multidemional returns but was wondering if I'm better...
5
28390
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through each element but I am having issues using redim to adjust the new array. Any help or example code would be greatly appreciated. thanks!
1
4865
by: dotnetnoob | last post by:
i have a arraylist that store String() array the string array hold value 1 2 4 i want to access the string array that is inside the arraylist one arraylist item at the time i search up and down for a way to do this but i havn't come arcoss anything that can help with this problem.
8
71612
by: Pim75 | last post by:
Hello, I'm defining a string array like: Dim strArray() As String = {"1", "2"} Can I add some values to this string array later in the code? It's not clear to me how to do this. I hope someone can help me. Thanks in advance!
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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 we have to send another system
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.