• 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
2
Question by Emerald_Eel_Entertainment · Nov 23, 2016 at 06:28 PM · c#scripting beginner

What does < word > do?

I have been practicing C#, and I am aware that > is more than and < is less than, but I am unsure what they do when they are arranged like this:

 <RawImage>

I used RawImage as an example of a word that goes in between these two symbols but I am uncertain of what using both symbols this way does. If anybody could help clear things up for me I would be most grateful.

Comment
Add comment · Show 1
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 Glurth · Nov 25, 2016 at 06:32 AM 0
Share

Interesting to note: When using these symbols to generate boolean expressions: the expression, " a c" is, in c#, not valid. For a valid boolean expression, one would need to use parenthesis, thereby "isolating" the greater/less than symbols e.g. "(a < b ) && (b > c)" This is one way the language syntax informs the compiler that the symbols are to be used as comparison operators, rather than type parameter "parenthesis".

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by AndreiMarian · Nov 23, 2016 at 07:59 PM

The word between <> represents the type, as tanoshimi explained. To get the big picture: they are used in generic methods, i.e. methods that were created with no particular type in mind, but with a generic type (usually denoted by T).
The behavior of these kind of methods depends on the user specified type: if you for example specify like method<int> the method, although it's named exactly the same, behaves differently as method<float>; the method code is the same, working "blindly" with whatever type is passed. It's transparent to the user (ok, programmer).
It's like overloading.
The differences lie in the use cases:
- overloading is used when the per type behaviors are very different from each other while generics is used when the behavior is the same for any type the user would input.
- overloading is used for a well determined number of types while generics is used when the designer has no idea of the future various types the methods/class would accept.

You can also create your own generic classes and methods. For more info take a look here:
https://msdn.microsoft.com/en-us/library/512aeb7t.aspx
https://www.tutorialspoint.com/csharp/csharp_generics.htm

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 Emerald_Eel_Entertainment · Nov 24, 2016 at 03:48 PM 0
Share

Ah, thank you for elaborating further!

avatar image Bunny83 · Nov 24, 2016 at 06:33 PM 1
Share

I think you mixed the concept of "overloading" with "overriding". Overloading has no relation to polymorphism. Polymorphism / overriding means that you have one base interface / class and many implementations / derived classes of it. So you're simply using the base interface not knowing what's actually behind it.

Overloading on the other hand is kind of the opposite ^^. You have two or more distinct methods which just share the same name but have no relation to each other. The compiler actually staticly links overloaded methods based on the parameter types passed when calling the method.

 // overloading:
 void $$anonymous$$y$$anonymous$$ethod()
 {
     Debug.Log("$$anonymous$$y $$anonymous$$ethod without parameters");
 }
 void $$anonymous$$y$$anonymous$$ethod(int someInt)
 {
     Debug.Log("$$anonymous$$y $$anonymous$$ethod with int parameter: " + someInt);
 }
 void $$anonymous$$y$$anonymous$$ethod(float someFloat)
 {
     Debug.Log("$$anonymous$$y $$anonymous$$ethod with float parameter: " + someFloat);
 }
 
 // somewhere else
 $$anonymous$$y$$anonymous$$ethod(); // will call the first implementation
 $$anonymous$$y$$anonymous$$ethod(42); // will call the second implementation
 $$anonymous$$y$$anonymous$$ethod(42f); // will call the third implementation

Also this sentence is a bit misleading:

The behavior of these kind of methods depends on the user specified type

I'm not sure what you understand by "behaviour" but a generic method does the same regardless of the type parameter. All it alters is the type it works with. So it's "almost" like a normal parameter but ins$$anonymous$$d of passing data it "passes" a type the method can work with.

avatar image AndreiMarian Bunny83 · Nov 27, 2016 at 10:06 PM 0
Share

You're right about overloading and polymorphism, I stand corrected. I've also corrected my answer.

avatar image
5

Answer by tanoshimi · Nov 23, 2016 at 06:33 PM

It's a type parameter, which is used when you need to pass a type of object (rather than a specific instance of an object) as a parameter.

 // Here, the <int> parameter is used to specify that myListOfInts is a list of ints 
 List<int> myListOfInts = new List<int>();

 // Here, <Rigidbody> means that GetComponent should only return the rigidbody component of the
 // attached object. 
 GetComponent<Rigidbody>();

In the above examples, int and Rigidbody are both types, and <int> and <Rigidbody> is how they are passed as parameters to the List constructor and GetComponent method.

Comment
Add comment · Show 1 · 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 Emerald_Eel_Entertainment · Nov 23, 2016 at 07:31 PM 0
Share

I think I understand a lot better now. Thank you very much! :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Different language scripts - how to avoid trouble? 1 Answer

Leap Motion-Beginner Scripting Issues 1 Answer

PlayerMovement and PlayerShooting Scripts 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