I've put some strings into a stack, and now I want to convert the stack to an string based array. Here's what I'm trying to do (this returns a cast error)
string[] results = (string)resultS tack.ToArray();
I've tried casting it as a string, an array of strings... no luck. ideas? 5 1892
AC,
There are different ways to do this, One of them may be.
//define new string array with the size of object array
string [] strArray= new string [objArray.Length];
//loop it out and fill the values
for(int j=0;j<strArray. Length;j++)
{
strArray[j] = new string(objArray[j].ToString().ToC harArray());
}
--
Shak
(Houston)
"AC" <sp**@aNOSPAMME connell.com> wrote in message
news:Ou******** ******@tk2msftn gp13.phx.gbl...
I've put some strings into a stack, and now I want to convert the stack to
an string based array. Here's what I'm trying to do (this returns a cast
error)
string[] results = (string)resultS tack.ToArray();
I've tried casting it as a string, an array of strings... no luck. ideas?
Thanks for the reply... I am looking for an explicit cast option. This is
one option (brute force) I was hoping to avoid.
-AC
"Shakir Hussain" <sh**@fakedomai n.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. AC,
There are different ways to do this, One of them may be.
//define new string array with the size of object array string [] strArray= new string [objArray.Length];
//loop it out and fill the values for(int j=0;j<strArray. Length;j++) { strArray[j] = new string(objArray[j].ToString().ToC harArray()); }
-- Shak (Houston)
"AC" <sp**@aNOSPAMME connell.com> wrote in message news:Ou******** ******@tk2msftn gp13.phx.gbl... I've put some strings into a stack, and now I want to convert the stack to an string based array. Here's what I'm trying to do (this returns a cast error)
string[] results = (string)resultS tack.ToArray();
I've tried casting it as a string, an array of strings... no luck. ideas?
AC <sp**@aNOSPAMME connell.com> wrote: I've put some strings into a stack, and now I want to convert the stack to an string based array. Here's what I'm trying to do (this returns a cast error)
string[] results = (string)resultS tack.ToArray();
I've tried casting it as a string, an array of strings... no luck. ideas?
string[] results = (string[])resultStack.To Array(typeof(st ring));
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Makes sense when yo usee the answer. Thanks John. Wasn't aware .ToArray()
took an optional parm on what to case the array as.
-AC
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... AC <sp**@aNOSPAMME connell.com> wrote: I've put some strings into a stack, and now I want to convert the stack to an string based array. Here's what I'm trying to do (this returns a cast error)
string[] results = (string)resultS tack.ToArray();
I've tried casting it as a string, an array of strings... no luck. ideas?
string[] results = (string[])resultStack.To Array(typeof(st ring));
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Not a cast, really: the parameter tells ToArray what sort of array to
create. Shakir's solution
//define new string array with the size of object array
string [] strArray= new string [objArray.Length];
//loop it out and fill the values
for(int j=0;j<strArray. Length;j++)
{
strArray[j] = (string)objArra y[j];
}
is more or less what ToArray() does internally, with the expected result if
some member of the array isn't a string (i.e. an exception).
"AC" <sp**@aNOSPAMME connell.com> wrote in message
news:eu******** ******@tk2msftn gp13.phx.gbl... Makes sense when yo usee the answer. Thanks John. Wasn't aware
..ToArray() took an optional parm on what to cast the array as.
-AC
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message news:MP******** *************** *@msnews.micros oft.com... AC <sp**@aNOSPAMME connell.com> wrote: I've put some strings into a stack, and now I want to convert the stack to an string based array. Here's what I'm trying to do (this returns a cast error)
string[] results = (string)resultS tack.ToArray();
I've tried casting it as a string, an array of strings... no luck. ideas?
string[] results = (string[])resultStack.To Array(typeof(st ring));
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vinodh Kumar |
last post by:
I see that casting changes the value of a pointer in case of multiple
inheritance.In single inheritance also it is the same know?Isn't it?
Vinodh Kumar P
|
by: Jacob Jensen |
last post by:
This question has probably been asked a million time, but here it comes
again. I want to learn the difference between the three type cast operators:
static_cast, reinterpret_cast, dynamic_cast. A good way to do this is by
example. So I will give an example and please tell me what you think:
I have a base
class A
with a virtual destructor, and a
class B
that is it inherits publicly from A and defines som extra stuff.
|
by: yufufi |
last post by:
lets say we have a 'shape' class which doesn't implement IComparable
interface..
compiler doesn't give you error for the lines below..
shape b= new shape();
IComparable h;
h=(IComparable)b;
but it complains for the following lines
|
by: Marco |
last post by:
I need to get a iterator from any generic collection.
public class .... GetIterator(Object collection)
{
.....
}
|
by: Ken Allen |
last post by:
I am relatively new to .Net, but have been using VB and C/C++ for years.
One of the drawbacks with VB6 and earlier was the difficulty in casting a
'record' to a different 'shape' so one could perform different manipulations
on it. For example, I have a complex data structure, which I can represent
in a VB6 TYPE declaration, but I cannot easily convert that to a fixed
length array of unsigned bytes so that I could perform a checksum...
| |
by: René Nordby |
last post by:
Hi there,
Is there anyone that knows how to do the following?
I have a class A and a class B, that 100% inherits from class A (this means
that I don't have other code in class B, than the Inherit statement).
|
by: William S Fulton |
last post by:
I'm looking for the name of the following casting style in order to do
some reading around on it and why it is sometimes used.
unsigned long long ull = 0;
void * ptr = 0;
ull = *(unsigned long long*)&ptr;
As opposed to the more usual casting:
|
by: madumm |
last post by:
Hi all
I really need a solution for the following::
-------------------------------------------------------------------------------------
Say i have a font object called 'myFont' as shown below;
Font myFont= domainAxis.getTickLabelFont();
I need to cast "myFont" object into a "Element" object as i shown below
|
by: Taras_96 |
last post by:
Hi everyone,
I was experimenting with static_cast and reinterpret cast
#include <iostream>
struct A1 { int a; };
struct A2 { double d; };
struct B : public A1, A2
|
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= |
last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting
more often than creating an instance of objects.
like :
protected void gvOrderDetailsRowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
switch (((Sale)e.Row.DataItem).SzPN)
{
|
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...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |