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 3 2222
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
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
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);
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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;
...
|
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
|
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))...
|
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 :-).
...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |