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 uanmanarmy · Aug 06, 2014 at 09:51 AM · c#random.rangenamespace

Namespace order c#.

Hi guys. Im having some problems here with using namespaces.

I need this 3 namespaces.

 using System;  //for Array
 using System.Collections; //For Random.Range and IEnumerators
 using System.Collections.Generic; // For List

My problem is that If I'm deleting System than I can work with Random.Range and I can't find Array, if I'm deleting System.Colections, I can work with Arrays but I can't find Random.Range and Ienumerator.

Is there a way to place this namespaces in a specific order or how should I face this problem?

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

2 Replies

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

Answer by MaT227 · Aug 06, 2014 at 09:58 AM

The order of namespaces is not important. You can find a lot of informations concerning namespaces like this one C# - Namespaces

It seems that your problem concerns the Random class because there is a conflict between System.Random and UnityEngine.Random.

When you face those kind of conflicts, you need to specify the namespace when you call for an object or a function.

 System.Random().Whatever();
 // or
 UnityEngine.Random().Whatever();


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 uanmanarmy · Aug 06, 2014 at 10:17 AM 0
Share

Thank you, I get it now! At first when I wrote the problem here, It wasn't showing me in the console that There is a conflict between this to Random Classes. Now it's shows and I figured out, thank you again.!

avatar image
2

Answer by vexe · Aug 06, 2014 at 09:59 AM

Who said order matters?

With the System namespace you have access to the System.Random With System.Collection you have access to the non-generic versions of all collections (including IEnumerator etc) - So Random isn't located in System.Collections but just System.

And one more thing, don't use the Array or ArrayList classes, they're legacy stuff. Left-overs from old C# versions. They're slow because of boxing and unboxing (which is solved when MS introduced generics)

About the Random class, there's a System.Random and a UnityEngine.Random - I think you want the latter. But, if you're adding references to both the namespaces and you type "Random" you'll get an error saying the call is ambiguous. You could either explicitly mention UnityEngine.Random (or System.Random) or you could just add an alias:

 using System;
 using etc;
 using Random = UnityEngine.Random;

And then just say "Random" and it would resolve to UnityEngine.Random

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 uanmanarmy · Aug 06, 2014 at 10:16 AM 0
Share

Thank you, Im using just to get the index from a specific position in the Array, not for something else.

avatar image vexe · Aug 06, 2014 at 10:22 AM 0
Share

Yes just use a regular array:

 Vector3[] vectors;
 int[] ints;
 etc[] etcs;


Or generics:

 List<Vector3> vectors;
 List<etc> etcs;

avatar image poliman · Feb 10, 2015 at 11:16 PM 0
Share

using Random = UnityEngine.Random; //aliases are time savers :)

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

23 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

Related Questions

Multiple Cars not working 1 Answer

C# Unity 3D Using functions from other files. 1 Answer

A node in a childnode? 1 Answer

Distribute terrain in zones 3 Answers

Using Coroutines to increase Float values C# 3 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