Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ByteVault · Mar 12, 2014 at 08:20 PM · arrayliststringifcomparison

C# ArrayList match to string?

Hi, I've been looking around now to see how I can or even If I can convert a ArrayList to a string and match it with another?

By making an output on DataStore[5] I get the number 1 or 0 as defined

(This is not the complete script but the important part.)

 ArrayList DataStore = new ArrayList();
 
 DataStore.AddRange(Regex.Split(info.text, "->"));
 
 if(DataStore[5] == "1") // Error is here. 
 {
 
      DisplayStrings = "Yes, its 1.";
 
 }
 else
 {
 
      DisplayStrings = "No, it's not 1.";
 
 }

Possible unintended reference comparison. Consider casting the left side of the expression to `string' to compare the values

How do I make this work?

It's propably really simple but right now I'm really tired and need a fresh pair of eyes.

Thanks in andvance!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image perchik · Mar 12, 2014 at 08:23 PM 0
Share

I wonder if the problem isn't that you're trying to do ArrayList.AddRange() on a string[] ...Not sure if string[] inherits from ICollection

avatar image ByteVault · Mar 12, 2014 at 08:43 PM 0
Share

I really would not know. Thanks for trying tho :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by stevethorne · Mar 12, 2014 at 08:31 PM

The error tells you what you need to do. Did you try casting DataStore[5] to a string? I try to avoid ArrayLists and use Lists instead so that it knows what types are coming in.

 if ( ( ( string ) DataStore[5] ) == "1" )
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ByteVault · Mar 12, 2014 at 08:44 PM 0
Share

Thanks, It worked like a sharm! Would I be able to change ArrayLists to Lists or would there be more to change?

avatar image stevethorne · Mar 12, 2014 at 08:45 PM 0
Share

Sure! Just create it like this.

 List<string> DataStore = new List<string>();

Continue using everything else the way you have it, and this way you wont need to cast each entry to a string because it already knows what it is.

avatar image ByteVault · Mar 12, 2014 at 08:49 PM 0
Share

Huh, Look at that. Seems like I started from the wrong end. I will look in to this tomorrow, right now I really need some sleep. Thanks for the fast answer. $$anonymous$$y script is now working as it should!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

if a string has certain letter(s) or number(s) 2 Answers

How To Assign List Elements To Array Elements? 2 Answers

How to save and load a list (containing string data) with playerpref ? 1 Answer

Value will not return from ArrayList, C# 1 Answer

How to check if the string is on a text file 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges