473,403 Members | 2,366 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,403 software developers and data experts.

C# array issue

Daxthecon
Expand|Select|Wrap|Line Numbers
  1. foreach (SearchResult result in search.FindAll())
  2.         {
  3.  
  4.             //pieces = result.Properties["samaccountname"][0].ToString().Split(new Char[] { '\'' });
  5.             //for (int i = 0; i < pieces.GetLength(0); i++)
  6.             //{
  7.                 //name = name + pieces[i];
  8.             //}
  9.  
  10.             manager.Items.Add(new ListItem(name, result.Properties["samaccountname"][0].ToString()));
  11.  
  12.             name = "";
This bit of code take the aduser samaccount and gets the number of characters and sets an absolute length for the drowdownlist(manager) to display the names. Well it has stopped working and I have no clue why.

The errors are as follows: Cannot implicity convert type 'string[]' to 'string'
'string' does not contain a definition for 'GetLength'

Any help asap would be really nice.
Sep 10 '08 #1
14 1845
Curtis Rutland
3,256 Expert 2GB
Well, you didn't show us the definition of pieces, but I believe that pieces is delcared as a string, and you are trying to use it as an array.

Make sure that pieces is defined as a string[].

Also, I'm not sure why all your code is commented out.
Sep 10 '08 #2
Well, you didn't show us the definition of pieces, but I believe that pieces is delcared as a string, and you are trying to use it as an array.

Make sure that pieces is defined as a string[].

Also, I'm not sure why all your code is commented out.
The whole thing was crashing and I wanted to see if it still worked without this and it just displays a small drowdown list with no names but a scroll bar and space for names. Could you be more specific about pieces to be defined as string[]. This isn't my code it was the guys before me and I am clueless on c#.

Also this is the only place pieves is used. Everything you see is everything you get.
Sep 10 '08 #3
Plater
7,872 Expert 4TB
It actually doesn't look like .NET?
I've never used GetLength() before, always just used .Length

string[] .Length will return the number of elements in the array (number of strings in the array)
string .Length returns the number of characters in the string.
Sep 10 '08 #4
It actually doesn't look like .NET?
I've never used GetLength() before, always just used .Length

string[] .Length will return the number of elements in the array (number of strings in the array)
string .Length returns the number of characters in the string.
When I used .Length and it needs more specific parameters in my opinion. Like I said C# is not my cup of tea and this is old .NET. This program is a few years old with hardcoded emails and such. Well one day after I loaded VS 2008 up and opened the IIS and edited one of the emails it was sending too(I am in the middle of writing all these programs correctly for future reference) and saved it and it didn't work. And ever since have had this issue. I need to get it done because people are unhappy that it's not working and I hadn't realized it wasn't working until just a few days ago.
Sep 10 '08 #5
Curtis Rutland
3,256 Expert 2GB
Did this use to work? or has it never worked?

pieces has to be defined somewhere. Right click on it and select "go to definition" or something like that.

@Plater:
Maybe it's this method, but I've never seen it either.
Sep 10 '08 #6
I forgot it wasn't in my copied code. But it's still not all that helpful.


Expand|Select|Wrap|Line Numbers
  1. DirectoryEntry entry = new DirectoryEntry("LDAP://OU=DAXCON,DC=hq,DC=local", "username", "password");
  2.         DirectorySearcher search = new DirectorySearcher(entry);
  3.  
  4.         search.Filter = "(&(objectclass=organizationalPerson) (mail=*daxcon.com)(!(useraccountcontrol=514)) (sn=*) (samaccountname=*) (!(extensionAttribute15=*)))";
  5.  
  6.         search.PropertiesToLoad.Add("samaccountname");
  7.         search.PropertiesToLoad.Add("mail");
  8.         search.PropertiesToLoad.Add("name");
  9.         search.PropertiesToLoad.Add("sn");
  10.  
  11.         search.Sort.PropertyName = "sn";
  12.  
  13.         string pieces;
  14.         string name = "";
  15.  
  16.         foreach (SearchResult result in search.FindAll())
  17.         {
  18.  
  19.             pieces = result.Properties["samaccountname"][0].ToString().Split(new Char[] { '\'' });
  20.             for (int i = 0; i < pieces.GetLength(0); i++)
  21.             {
  22.                 name = name + pieces[i];
  23.             }
  24.  
  25.             manager.Items.Add(new ListItem(name, result.Properties["samaccountname"][0].ToString()));
  26.  
  27.             name = "";
  28.  
  29.         }
  30.  
  31.         entry.Close();
  32.     }
Trust me before the fanatics see the amount of bad this isn't mine and I am dedicating learning and redoing all of this code and AD paths and what not. With that being said that is the code and how it is displayed as of right now and as of when it worked for as much as I know.
Sep 10 '08 #7
Plater
7,872 Expert 4TB
Ok, this line:
Expand|Select|Wrap|Line Numbers
  1. string pieces;
  2.  
should be change to
Expand|Select|Wrap|Line Numbers
  1. string[] pieces;
  2.  
Since pieces is going to receive an array of strings from that split(). I believe that is what one of the error messages you are getting. Actually I think it will clear up both of them, since pieces will then be a string[], it will also contain the .GetLength() function.
HOWEVER, based on the apparent logic in that function, I would change .GetLength() to .Length anyway.
As GetLength(0) will return the number of characters in the first string contained in the pieces array, and not how many elements are in the array.
Sep 10 '08 #8
Stack trace says
; expected


I don't think I am missing a ; anywhere that I wasn't before.
Sep 10 '08 #9
Plater
7,872 Expert 4TB
If you were missing a in CODE code, doing abuild would throw up an error message in visual studio.
However, if you were missing a ; in some kind of query string or something, that might be harder to find.
Error messages should give you a line number?
Sep 10 '08 #10
Line 111

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < pieces.Length(0); i++)
which is also giving me a Method name expected error.
Sep 10 '08 #11
Plater
7,872 Expert 4TB
Ahh, oopsy. I should have told you that Length is a property, not a function. It does not require any arguments.

I am trying to figure out what that bit of code is doing.
It looks like it's taking this:
"something/someotherthing/somename"
and making it be
"somethingsomeotherthingsomename".

Seems like a lot of work that could have been handled with the .Replace() function.
Sep 10 '08 #12
Ahh, oopsy. I should have told you that Length is a property, not a function. It does not require any arguments.

I am trying to figure out what that bit of code is doing.
It looks like it's taking this:
"something/someotherthing/somename"
and making it be
"somethingsomeotherthingsomename".

Seems like a lot of work that could have been handled with the .Replace() function.
I got it working again and I have no idea how... I just did pieces. and GetLength was there... Now is there a way to do this without having to change a ton of things around like this code is doing.
Sep 10 '08 #13
Plater
7,872 Expert 4TB
I got it working again and I have no idea how... I just did pieces. and GetLength was there... Now is there a way to do this without having to change a ton of things around like this code is doing.
Expand|Select|Wrap|Line Numbers
  1. string[] pieces;
  2. string name = "";
  3.  
  4. foreach (SearchResult result in search.FindAll())
  5. {
  6.    name = result.Properties["samaccountname"][0].ToString().Replace("\","");
  7.    manager.Items.Add(new ListItem(name, result.Properties["samaccountname"][0].ToString()));
  8. }
  9.  
That is assuming you were splitting on the \ character.
Sep 10 '08 #14
What about VB.net. Would this little aray be easier to make or am I barking up the wrong tree. I am new to AD for the most part and can't get a web server to display AD stuff in a dropdownlist. But this project after it broke exhibited the same behavior as the project I was working on and was stuck on.
Sep 10 '08 #15

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

Similar topics

5
by: Nico | last post by:
Hello folks, I am currently storing a set of objects inside an array, $itemlist = array(); $itemlist = new item("myitem"); //... and I am looking to develop a search function, which...
9
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ...
29
by: shmartonak | last post by:
For maximum portability what should the type of an array index be? Can any integer type be used safely? Or should I only use an unsigned type? Or what? If I'm using pointers to access array...
4
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
33
by: Zytan | last post by:
I want to make a zero element array. I know that Nothing is not the same as a zero element array, since I can't get the length of, or iterate through, an array = Nothing. I could make a zero...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
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: 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
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
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...
0
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,...

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.