473,804 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

from List <double> to double[]

The following code works fine

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

foreach (double item in GetDataFor("Air Temp", 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.DateTim e'

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 13999
Web learner <be******@learn ing.edu> wrote:
The following code works fine

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

foreach (double item in GetDataFor("Air Temp", 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.DateTim e'

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("Air Temp", selectedYear);
for (int i=0; i < list.Length; i+=2)
{
DateTime date = DateTime.FromOA Date(list[i]);
double airTemp = list[i+1];
}

--
Jon Skeet - <sk***@pobox.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Web learner <be******@learn ing.edu> wrote:
The following code works fine

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

foreach (double item in GetDataFor("Air Temp", 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.DateTim e'

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("Air Temp", selectedYear);
for (int i=0; i < list.Length; i+=2)
{
DateTime date = DateTime.FromOA Date(list[i]);
double airTemp = list[i+1];
}

--
Jon Skeet - <sk***@pobox.co m>
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(DateT ime 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("Air Temp", selectedYear))
{
Response.WriteL ine("{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
2277
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 foo containing vectors of the size 3. I then want to compare a vector<double> of size 3 (coord) with foo to find a sequence of elements in foo that equals coord. However, when I try this it returns when just one of the element of coord equals one...
20
17843
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; std::vector<double>::size_type size = src.size(); dest.reserve(size); for (std::vector<int>::size_type i = 0;
14
2671
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
2235
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)) { Response.Write(item.ToString() + ", ");
7
12379
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 :-). #include <iostream> #include <vector> using namespace std;
6
1561
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 argument. The naive way below does not work. list<Bar<double>myList; It produces the error message: Error: "," expected instead of ">>". How
3
6180
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 the real part of a complex number, elements with odd indices represent the imaginary part. I actually need an array of length N of type complex<double>. Obviously, I could copy the data and destroy the first array, but this is an expensive option....
32
4046
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 large amount of data, that I read off using an ifstream object, I don't want to use the push_back method because this grows the vector<vector<double>dynamically, and that will kill my execution time. So, I want to reserve space first, using, of...
5
6058
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 use it, but std::sort doesn't seem to find it. I have copied a very simple example below. Everything compiles just fine when the line with std::sort function is commented out, but with that line included a whole slew of errors are given like: ...
0
9704
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...
0
9571
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,...
0
10561
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, 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...
0
10069
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
9132
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
7608
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
6845
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4277
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
2
3803
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.