473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

from List <double> to double[]

The following code works fine

private List<double> GetDataFor(string column, int selectedYear) {
-------
-------
return list;
}

foreach (double item in GetDataFor("AirTemp", selectedYear)) {
Response.Write(item.ToString() + ", ");
}

It shows data as follows:

37987, -2.42, 37988, -2.41, 37989, -3.34,....................................

where the five digit numbers correspond to date (the first one for 01 Jan 2004) and the decimal negative number as AirTemp. As you can see both are of type double.

I have to use this returned "list" of type double as follows:

double[] date = (DateTime)item; // ERROR Cannot convert type 'double' to 'System.DateTime'

double[] AirTemp = (double)item[1]; //

The above gives me error. I am confused:( what to do. There must be much better and elegant way to do this.

the Web_learner
Apr 25 '06 #1
3 13866
Web learner <be******@learning.edu> wrote:
The following code works fine

private List<double> GetDataFor(string column, int selectedYear) {
-------
-------
return list;
}

foreach (double item in GetDataFor("AirTemp", selectedYear)) {
Response.Write(item.ToString() + ", ");
}

It shows data as follows:

37987, -2.42, 37988, -2.41, 37989, -3.34,....................................

where the five digit numbers correspond to date (the first one for 01
Jan 2004) and the decimal negative number as AirTemp. As you can see
both are of type double.
Hmm - do you *have* to return them as a list of doubles? It doesn't
feel like it's the right way of doing things. Anyway.
I have to use this returned "list" of type double as follows:

double[] date = (DateTime)item; // ERROR Cannot convert type 'double' to 'System.DateTime'

double[] AirTemp = (double)item[1]; //


Why are you declaring the variables to be arrays of doubles? I would
expect you'd want:

double[] list = GetDataFor("AirTemp", selectedYear);
for (int i=0; i < list.Length; i+=2)
{
DateTime date = DateTime.FromOADate(list[i]);
double airTemp = list[i+1];
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 25 '06 #2
That is what I wanted.

You showed me the correct and precise way.

Thanks ....!

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Web learner <be******@learning.edu> wrote:
The following code works fine

private List<double> GetDataFor(string column, int selectedYear) {
-------
-------
return list;
}

foreach (double item in GetDataFor("AirTemp", selectedYear)) {
Response.Write(item.ToString() + ", ");
}

It shows data as follows:

37987, -2.42, 37988, -2.41,
37989, -3.34,....................................

where the five digit numbers correspond to date (the first one for 01
Jan 2004) and the decimal negative number as AirTemp. As you can see
both are of type double.


Hmm - do you *have* to return them as a list of doubles? It doesn't
feel like it's the right way of doing things. Anyway.
I have to use this returned "list" of type double as follows:

double[] date = (DateTime)item; // ERROR Cannot convert type 'double' to
'System.DateTime'

double[] AirTemp = (double)item[1]; //


Why are you declaring the variables to be arrays of doubles? I would
expect you'd want:

double[] list = GetDataFor("AirTemp", selectedYear);
for (int i=0; i < list.Length; i+=2)
{
DateTime date = DateTime.FromOADate(list[i]);
double airTemp = list[i+1];
}

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

Apr 25 '06 #3
Well, Actually the "correct & precise" way would be for GetDataFor() to
return an List of "DateValue" objects defined like:
class DateValue
{
private DateTime oDate;
private double oValue;
public DateValue(DateTime date, double value)
{
oDate=date;
oValue = value;
}
public DateTime Date
{
get
{
return oDate;
}
}
// Add Similar property getter for Value
}

Then you can read the data as:

foreach (DateValue item in GetDataFor("AirTemp", selectedYear))
{
Response.WriteLine("{0} -- {1}", item.Date, item.Value);
}

Apr 26 '06 #4

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

Similar topics

1
by: Dennis | last post by:
Hi I'm trying to implement a vector of vectors where find can be used to find a vector<double> in the vectors of vectors, that is hard to understand i guess. What I mean is that I got a vector...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
14
by: LumisROB | last post by:
Is it possible to create matrixes with vector <vector <double >> ? If it is possible which is the element m23 ? You excuse but I am not an expert Thanks ROB
3
by: Web learner | last post by:
The following code works fine private List<double> GetDataFor(string column, int selectedYear) { ------- ------- return list; } foreach (double item in GetDataFor("AirTemp", selectedYear))...
7
by: utab | last post by:
Dear all, I tried sth like this, compiles but segmentation fault error. In my reasoning field_values holds a vector<double> but when I tried, I understood that it is not the case :-). ...
6
by: janzon | last post by:
Hi I have a class Foo that I use both as a Foo<doubleand a Foo<float>. I want to put instances of this class in a list container. The list container itself is a template and need a type...
3
by: J.M. | last post by:
I have data in a double array of length 2N, which actually represents complex numbers with real and imaginary parts interlaced. In other words, elements in this array with even indices represents...
32
by: T. Crane | last post by:
Hi, I'm struggling with how to initialize a vector<vector<double>> object. I'm pulling data out of a file and storing it in the vector<vector<double>object. Because any given file will have a...
5
by: jeremit0 | last post by:
I'm trying to sort a vector<complex<double and can't figure it out. I recognize the problem is that there isn't a default operator< for complex data types. I have written my own operator and can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...

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.