On Thu, 14 Aug 2008 18:56:00 -0700, Phill
<Ph***@discussi ons.microsoft.c omwrote:
I have a table that contains 7 row of data with 8 columns. The columns
contain decimal data. Looks like this:
1 .5 .5 0 0 0 0 0 0
2 .25 .25 .25 0 0 0 0 0
etc.
The first column tells me how many points and I will use this as my
index in
the array. I want to load this table into an array to be used in some
calculations and i don't want to have to read the database everytime they
change the number of points to calculate. I am new to c# and am having
a lot
of trouble declaring my array and populating it. This is what I have so
far
but it won't compile because the array is defined wrong..I think???
For future reference, if you are asking for help with an error (compile or
execution), you really should post the complete text of the error and be
specific about when and where it happens.
That said, in your code it's clear what's wrong:
double[,] arrULD=new int[8];
If you declare a multi-dimensional array, you have to allocate one. And
you can't allocate just one dimension. A proper allocation would look
like "new int[rows, 8]" (if "rows" contains the number of rows you want)
or "new int[7, 8]" (if you know ahead of time you want 7 rows), or
whatever.
Now, that said, based on the code you posted, it seems as though maybe you
don't really want a multidimensiona l array anyway. In your loop, you are
setting an element of a single-dimension array to an instance of another
single-dimensional array. For that, your array initialization would look
more like this:
double[][] arrULD = new double[][7]; // 7 rows of data
Then the code in your loop would work fine.
Finally, don't forget that C# arrays are 0-based. :)
Pete 4 1655
Thanks for the response. This line is still giving an error:
while (rdr.Read())
{
arrULD[(int)rdr["NumberOfPoints "]] = {rdr[0],rdr[1]};
//{rdr[0],rdr[1]};
}
The error is ";" expected in this part {rdr[0],rdr[1]};
"Peter Duniho" wrote:
On Thu, 14 Aug 2008 18:56:00 -0700, Phill
<Ph***@discussi ons.microsoft.c omwrote:
I have a table that contains 7 row of data with 8 columns. The columns
contain decimal data. Looks like this:
1 .5 .5 0 0 0 0 0 0
2 .25 .25 .25 0 0 0 0 0
etc.
The first column tells me how many points and I will use this as my
index in
the array. I want to load this table into an array to be used in some
calculations and i don't want to have to read the database everytime they
change the number of points to calculate. I am new to c# and am having
a lot
of trouble declaring my array and populating it. This is what I have so
far
but it won't compile because the array is defined wrong..I think???
For future reference, if you are asking for help with an error (compile or
execution), you really should post the complete text of the error and be
specific about when and where it happens.
That said, in your code it's clear what's wrong:
double[,] arrULD=new int[8];
If you declare a multi-dimensional array, you have to allocate one. And
you can't allocate just one dimension. A proper allocation would look
like "new int[rows, 8]" (if "rows" contains the number of rows you want)
or "new int[7, 8]" (if you know ahead of time you want 7 rows), or
whatever.
Now, that said, based on the code you posted, it seems as though maybe you
don't really want a multidimensiona l array anyway. In your loop, you are
setting an element of a single-dimension array to an instance of another
single-dimensional array. For that, your array initialization would look
more like this:
double[][] arrULD = new double[][7]; // 7 rows of data
Then the code in your loop would work fine.
Finally, don't forget that C# arrays are 0-based. :)
Pete
On Thu, 14 Aug 2008 21:42:03 -0700, Phill
<Ph***@discussi ons.microsoft.c omwrote:
Thanks for the response. This line is still giving an error:
while (rdr.Read())
{
arrULD[(int)rdr["NumberOfPoints "]] = {rdr[0],rdr[1]};
//{rdr[0],rdr[1]};
}
The error is ";" expected in this part {rdr[0],rdr[1]};
Sorry, yes...the short-hand collection notation is allowed only in
initializers. Change the right-hand-side to "new double[] { rdr[0],
rdr[1] }" and it should work.
For future reference, you should become familiar with the C# language
reference on MSDN. It has lots of information about basic syntax for
expressions, assignments, declarations, etc.
Pete
Thanks, I have looked at many sample, none are helping me though. Now I get
error saying cannot convert type double[] to double on this line:
arrULD[(int)rdr["NumberOfPoints "]] = new double[] {
(double)rdr[0], (double)rdr[1], (double)rdr[2], (double)rdr[3],
(double)rdr[4], (double)rdr[5], (double)rdr[6] };
This should not be rocket science....urrr r
"Peter Duniho" wrote:
On Thu, 14 Aug 2008 21:42:03 -0700, Phill
<Ph***@discussi ons.microsoft.c omwrote:
Thanks for the response. This line is still giving an error:
while (rdr.Read())
{
arrULD[(int)rdr["NumberOfPoints "]] = {rdr[0],rdr[1]};
//{rdr[0],rdr[1]};
}
The error is ";" expected in this part {rdr[0],rdr[1]};
Sorry, yes...the short-hand collection notation is allowed only in
initializers. Change the right-hand-side to "new double[] { rdr[0],
rdr[1] }" and it should work.
For future reference, you should become familiar with the C# language
reference on MSDN. It has lots of information about basic syntax for
expressions, assignments, declarations, etc.
Pete
On Fri, 15 Aug 2008 19:22:11 -0700, Phill
<Ph***@discussi ons.microsoft.c omwrote:
Thanks, I have looked at many sample, none are helping me though. Now I
get
error saying cannot convert type double[] to double on this line:
arrULD[(int)rdr["NumberOfPoints "]] = new double[] {
(double)rdr[0], (double)rdr[1], (double)rdr[2], (double)rdr[3],
(double)rdr[4], (double)rdr[5], (double)rdr[6] };
That suggests that "arrULD" is declared as "double[]" rather than
"double[][]". Unfortunately, you haven't shown all of the code, so
there's no way for us to say exactly what's wrong for sure.
I'm also a little confused, since your first post said you have 7 rows and
8 columns of data, but you seem to be defining here a row of data with 7
columns. But that wouldn't be the compiler error issue, so maybe I
shouldn't concern myself with that.
Pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stefan Richter |
last post by:
Hi,
I want to create an associative Array with a PHP variable (article ID)
as Key
and another associative array as it's value.
How do I instanciate it, how can I fill it?
I want something like this:
|
by: Friday |
last post by:
Sorry if this is the wrong group. I tried to find the one I thought
would be most relevant.
I'm an old PHP guy, who knows little about asp and NOTHING about
asp.net, but need to learn at least enough to convert a favorite PHP
script to work on an ASP.NET site.
I'm experimenting with simple example scripts that will help me learn
how to implement each "piece" of the puzzle.
|
by: r5 |
last post by:
I'm using the MIPSpro Compiler and having trouble defining
a function template (involving array size specifiers as
template arguments) inside a class. The same definition
compiles fine outside the class. I have listed a short
sample code and resulting error messages at the end of
this posting.
Is there a known work-around that fixes this "inside
the class" problem for SGI compilers -- short of
upgrading beyond v7.2.1?
|
by: elmoizwaly |
last post by:
hi there
i am new to vb
i have a new project (mdi) with 8 child forms evry form with at least
10 textboxs.
the problem is that when building an array for each form textboxs and
declaring the array as public i can't get the data enterd in other
forms to be printed as a single document.
any one have a solution?
thanks in advance.
|
by: Martin Jørgensen |
last post by:
Hi,
"C primer plus" p.382:
Suppose we have this declaration:
int (*pa);
int ar1;
int ar2;
int **p2;
| |
by: cmt |
last post by:
I have an ASP report that returns values from a SQL database and
formats the data in an HTML table.
I am trying to figure out a good way of using CSS to highlight the
table row that contains the highest value returned.
I tried storing the values in an array, and then used a function to
find the highest value. This worked, but then I couldn't really
figure out how to "tell" the report to highlight that highest value.
|
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:
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,...
|
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...
|
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...
|
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.
|
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...
| |