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
1
Question by Fattie · Sep 09, 2013 at 09:30 AM · c#actiondelegates

c# (Unity flavour) Action, return value, error thereof

As I understand it (I am not a language mechanic) in c#, Action must return only void. So given

 public void teste( String s ) {}
 public int pesty( String s ) {}

Then if you have

 private Action<String> xx;

You can indeed say xx = teste, but you can never say xx = pesty.

ie, there is no syntax along the lines

 private Action ?int?<string> xx

In short (as far as I know, IANALM) in c# Action can only return void. (You can use "Func" if there's one argument and one return.)

Anyways, I just noticed that if you try xx=pesty, the resulting error in Unity is in fact,

CS0407: A method or delegate string testy(string)' return type does not match delegate void System.Action(string)' return type

..rather than something more like "you forgot that Actions must return void, dumbass". This perhaps suggests that maybe you CAN set a return type for Actions, in c# in Unity?

In short, is there anything I'm missing here, thanks!

Comment
Add comment
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

1 Reply

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

Answer by ArkaneX · Sep 09, 2013 at 09:41 AM

It's not C# in Unity only. If you did similar test in VS with non-Unity project, you'd get CS0407 as well. Even in the MSDN info related to this error, you'll find example with void. Although that example is reverse of the one provided by you.

So I think you're not missing anything and Action can return void only :)

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 Fattie · Sep 09, 2013 at 09:43 AM 0
Share

Ah - I guess the language of the error is broad enough to cover delegate, Action or Func. Well, I guess you've answered the question - that's a very useful link thanks! :)

avatar image ArkaneX · Sep 09, 2013 at 09:45 AM 0
Share

You're welcome :)

avatar image Fattie · Sep 09, 2013 at 09:47 AM 0
Share

Lol no thank YOU! ;-)

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

16 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Help filtering objects using delegates, passing methods to methods for delegate instancing 1 Answer

Unity 5.4.1 OnLevelWasLoaded Workaround for Singletons? 2 Answers

How can I invoke a Method Property from a MethodInfo (Reflection) while keeping it's properties and types generic? 2 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