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 Gatsua · Nov 22, 2014 at 06:11 PM · c#error

c# Exists() causing error CS0135

Why does the Exist() not work here?

 if(listOfPlayers.Exists(listOfPlayers => listOfPlayers.netID == uniqueId) == false)
 {
   foreach(NetworkUser user in listOfPlayers)
   {
     if(user.active == false)
     {
       user.netPlayer = Network.player;    // NetworkPlayer object
       uniqueId = user.netID;
       user.characterName = characterName;
       user.characterClass = characterClass;
       user.active = true;
       user.netPlayer = networkPlayer;
       user.characterLevel = characterLevel;
                     
       break;
     }
   }
 }


error on line 1:

error CS0135: listOfPlayers' conflicts with a declaration in a child block`

I have problems figuring out what this error means for me.

Comment
Add comment · Show 4
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 gjf · Nov 22, 2014 at 06:19 PM 0
Share

depends a lot on what type listOfPlayers is. it may not have that particular method available.

having said that - from the message, i don't think that's the error...

avatar image RadioactiveTechnologies · Nov 22, 2014 at 06:21 PM 0
Share

Could you please post the full script and the full error log?

avatar image flaviusxvii · Nov 22, 2014 at 06:22 PM 0
Share

I think you are assu$$anonymous$$g too much! Post more context and the original error message.

avatar image gjf · Nov 22, 2014 at 06:23 PM 0
Share

the error is there, but there's not enough context (code) to respond further.

1 Reply

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

Answer by Gatsua · Nov 22, 2014 at 06:39 PM

sorry, it was a simple syntax issue. This is how the Exists() should look like:

 if(listOfPlayers.Exists(item => item.netID == uniqueId) == false)
 {
   ...
 }
Comment
Add comment · Show 13 · 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 flaviusxvii · Nov 22, 2014 at 06:44 PM 0
Share

Style suggestion

Comparing values against true and false screams amateur. Exists() is returning a bool. if() takes a bool. No comparison necessary.

  if(!listOfPlayers.Exists(item => item.netID == uniqueId))
  {
    ...
  }

avatar image RadioactiveTechnologies · Nov 22, 2014 at 06:46 PM 0
Share

@flaviusxvii $$anonymous$$an, it doesn't really matter. Either way works.

avatar image Gatsua · Nov 22, 2014 at 07:02 PM 0
Share

@flaviusxvii Comparing to a bool or using ! does not deter$$anonymous$$e if a developer are an amateur or not. Often when I decide whether to use a bool or ! it's a matter of code clarity. eg when I use _.isUndefined() in JavaScript I prefer to use ! because in my head I read it as "not". As far as I know, there are no performance differences. Please correct me if im wrong.

Please elaborate with why I should rather do it your way.

avatar image gjf · Nov 23, 2014 at 03:44 PM 1
Share

a lot of it is personal preference - assu$$anonymous$$g that the code is functioning properly. whether to include comparisons to true or false is neither here nor there - as has been stated, the compiler will (usually) generate equivalent code.

it often has more to do with the developers experience and what is a familiar coding style. whilst i prefer something more concise (less code may be less likely to contain bugs or misunderstandings if others are involved), it depends on the individual. for me, it's more important that the code is clear in its' intent (negating the need for often superfluous, inaccurate or inane commenting) and easier to maintain, regardless of that poor soul being me or somebody else.

statements such as "Comparing values against true and false screams amateur." are not exactly helpful and really not in the spirit of unity answers. flame away if somebody is outright wrong, and feel free to suggest other approaches which work, but never be that guy!

here endeth the sermon...

ps i've been that guy ;)

avatar image Gatsua · Nov 25, 2014 at 03:22 PM 1
Share

Literally expressing what you do does add clarity to the code and it does help me and the people I work with, along with the graphical designers who might not have as experienced eyes for codes as you and me, to better see the picture. This is not superfluous code for this reason. I'm also quite good at commenting algorithms that might not be clear to the other coders reading the code. All of this prevents someone from having to re-read the section. The other day I had to spend 30 $$anonymous$$utes just understanding another persons 20 lines long search function due to a cryptic code style without any comments inside the block and that is obviously a waste of time when adding a little comment takes about 15 seconds in total and has no effect on the outcome of the app. I find it very important to type clear codes at all times, even if you are the lone coder of the project.

If you are going to give me a style suggestion you will have to come with a valid reason why I should start doing it your way. Because things such as "it's not pro" is far from a valid reason. Neither is it humorous to call me an amateur or fool I'm afraid and it's what you can call "not professional" or !professional, see the irony here?

I am curious and would love to know from both of you why literally and directly expressing the purpose is not more clear for you. I find the ! operator to be less clear to interprate simply because it negates a bool. For example:

 1. if(!isActive) { isActive = true; }
 2. if(isActive == false) { isActive = true; }

In my head I read these as:

1: "if not isActive is true, set isActive to true"

2: "if isActive is false, set isActive to true"

And number 2 makes more sense in my head. It's about saying that "something is false" then "something is not true". It feels like a more direct explanation then taking the detour of stating what it's not. Then ofcourse, this is just personal preference.

Show more comments

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

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Sync with visual studio 2010 error 1 Answer

No Monobehaviour scripts in files 1 Answer

2-Dimensional Array Error [CLOSED] 1 Answer


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