system.object[] convert to string

arik31

New member
system.object[] convert to string

שלום לכולם, אני מנסה לקבל את הנתונים שנמצאים במשתנה value שהוא מסוג system.object[] ואני לא מצליח!!! למישהו יש רעיון, אני אשמח לשמוע.
 

EdotK

New member
->

System.object[] value; String MyString; MyString = (String)value[0]; // or to get all the values in Value foreach(object obj in value) { (String)obj; }​
 

arik31

New member
זה בדיוק מה שעשיתי וזה לא עובד

במקרה הראשון אני מקבל את ההודעה הבאה: Cannot apply indexing with [] to an expression of type 'object' ובמקרה השני: foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
 

arik31

New member
ניסיתי, לא עובד ../images/Emo4.gif

ניסיתי גם string tty1 = (string)((string[])value)[0], וגם זה לא עובד.
 

arik31

New member
הודעות שגיאה שאני מקבל.

במקרה הראשון: String[] MyString = (String[])value; ההודעה היא: Unable to cast object of type 'System.Object[]' to type 'System.String[]'. במקרה השני: string tty1 = (string)((string[])value)[0]; ההודעה היא: Unable to cast object of type 'System.Object[]' to type 'System.String[]'.
 

EdotK

New member
יש לך טעות כלשהי כי אני מצליח

object[] hey = new object[10]; hey[1] = "hello"; string myString = (string)hey[1];​
הקוד הזה עובר קומפילציה ורץ יפה אצלי. תנסה להריץ את זה ותגיד לי אם הקוד הזה בכלל מתקמפל אצלך.
 

arik31

New member
הקוד עובד מצוין, אבל לא הקוד שלי.

אולי זה יעזור....את ה object אני מקבל: private object GetAttributeValue(string key, DirectoryEntry userEntry) object value = userEntry.Properties[key].Value; ואז אני מנסה להוציא את הנתונים מתוך value ולא מצליח.
 

arik31

New member
הצלחתי בעזרתך לפתור את הבעיה.

הוספתי: object[] value = (Object[])userEntry.Properties[key].Value;
 

EdotK

New member
אז צדקתי מלכתחילה

מה שהיה לך לא היה object[]. ואגב, תשתמש ב \הקוד\ כשאתה מראה קוד כי ממש קשה להבין אחרת.
 

24sharon

New member
ביקשת רעיון

אז עוד אחד. OBJECT כידוע יכול לקבל ערך NULL. והוא לא יכול להפוך לSTRING. תנסה לבדוק אם כל ערך במערך לא NULL ואז להפוך לSTRING. בהצלחה!
 

arik31

New member
וכמובן תודה לכולם!!! ../images/Emo13.gif

ותודה רבה מגיעה לך EdotK.
 
למעלה