473,386 Members | 1,741 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,386 software developers and data experts.

Cannot apply indexing to type System.Array?

10
C# APP
Basically i am trying to use indexing on an array that i have fed into a method as its parameter. Here is a simplified version of my code.

Expand|Select|Wrap|Line Numbers
  1. public void Inputs(string path)
  2. {
  3.             string line;
  4.             line = inputstream.ReadToEnd();
  5.             string[] words;
  6.             char[] seperators = { '\t', '\n' };
  7.             words = line.Split(seperators);
  8.  
  9.             listSeperation(words, line);
  10. }
  11. public void listSeperation(Array words, string line)
  12. {  
  13.             string[] UID = new string[studentlength];
  14.             int j=0;
  15.  
  16.             for (int i = 1; i < words.Length; i = i + 5)
  17.             {
  18.                 UID[j++] = words[i];  //error
  19.             }
  20. }
I get an error saying that it "Cannot apply indexing with [] to an expression of type System.Array" I cant see why there should be any problem with my code. Any help or advice would be great.

Thanks
Feb 27 '08 #1
4 26300
Plater
7,872 Expert 4TB
System.Array is a very base class for dealing with arrays (sorting, etc)
You could do it with
public void listSeperation(Array words, string line)
But you would have to use the .GetEnumerator() instead of indexing.

Instead, change your function protype to be this:
Expand|Select|Wrap|Line Numbers
  1. public void listSeperation(string[] words, string line)
  2.  
Also, you are not starting at the first spot in the array (which would be index 0) you are starting with the 2nd spot (index 1)

As we've had this conversation before, I again suggest you read some basics on arrays.
http://en.wikipedia.org/wiki/Array

As well as basics on program flow and logical statement creation.
Feb 27 '08 #2
Chiefy
10
System.Array is a very base class for dealing with arrays (sorting, etc)
You could do it with
public void listSeperation(Array words, string line)
But you would have to use the .GetEnumerator() instead of indexing.

Instead, change your function protype to be this:
Expand|Select|Wrap|Line Numbers
  1. public void listSeperation(string[] words, string line)
  2.  
Also, you are not starting at the first spot in the array (which would be index 0) you are starting with the 2nd spot (index 1)

As we've had this conversation before, I again suggest you read some basics on arrays.
http://en.wikipedia.org/wiki/Array

As well as basics on program flow and logical statement creation.

Thanks for the help, starting at 1 is intentional as i dont want the first part of the array as its the heading of the list
Feb 27 '08 #3
The correct answer is to use Array.GetValue(int index):

Expand|Select|Wrap|Line Numbers
  1. UID[j++] = words.GetValue(i);
  2.  
Jul 25 '10 #4
@Anton McCovovic
Yep this solution works. I had a similar issue read the response from Plater that did not make sense in my situation. The link he referenced was generic and did not apply specifically enough to the situation at hand. The response from Anton was concise and a huge help.

Thanks guys.
Aug 15 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Anita C | last post by:
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value =...
8
by: Bassem | last post by:
Hi to all... Thanks for the help... I want to get the value of the column of dataset into array, but I get this bug. "Cannot apply indexing with to an expression of type 'object'" when biuld....
3
by: Karel Vandenhove | last post by:
Hi, I get an error "cannot apply indexing with to an expression of type object" when I try to compile the code below. SSLScannerManager is a COM component. (Used to access fingerprint...
1
by: JH | last post by:
Dim SysInfo2 As System.Environment Dim OS As String With SysInfo2 Select Case .OSVersion
3
by: Adam J Knight | last post by:
Hi all, I am getting the following error with this if statement.. if(e.Item.DataItem != 2) { } //error Cannot apply indexing with to an expression of type 'object' Can someone fill me in on...
3
by: clawton | last post by:
Hi All - I've got a 3rd party COM object that returns an array of bytes that are a TIFF image. After adding the reference to the com object to my solution the C# signature for the method is...
2
by: Martin Pöpping | last post by:
Hello, I´m getting the above error with following lines of code: SortedList<int, intpreparedConcepts = prepareConcepts(docs); IList<intpreparedKeys = preparedConcepts.Keys; foreach (int key...
4
by: O.B. | last post by:
I have the following: public class Matrix3D { private const int SIZE = 3; public double matrix = new double; public static Matrix3D operator *(Matrix3D lhs, Matrix3D rhs) { Matrix3D result...
4
by: clflyer | last post by:
I have a small problem. I'm pretty much a newbie to C# coming out of VB.Net. I have a windows form that has a GroupBox named grpSoldTo. I want to be able to clear all the textboxes and comboxes...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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.