Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Cs1525 tell me whote is error

Discussion in 'Scripting' started by petea, May 14, 2014.

  1. petea

    petea

    Joined:
    Nov 29, 2013
    Posts:
    55
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NewBehaviourScript : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start ()
    8.     {
    9.  public static class IListExtensions {
    10.  
    11.    public static void Shuffle<T>(this IList<T> ts) {
    12.       var count = ts.Count;
    13.       var last = count - 1;
    14.      for (var i = 0; i < last; ++i) {
    15.          var r = UnityEngine.Random.Range(i, count);
    16.          var tmp = ts[i];
    17.          ts[i] = ts[r];
    18.          ts[r] = tmp;
    19.  
    20.      }
    21.  
    22.    }
    23. }
    24. }
    25. }
     
  2. TheMeanCoder

    TheMeanCoder

    Joined:
    Apr 25, 2014
    Posts:
    15
    You have a class inside a class. These should be separate classes.

    Code (csharp):
    1.  
    2.     using UnityEngine;
    3.     using System.Collections;
    4.      
    5.     public class NewBehaviourScript : MonoBehaviour {
    6.      
    7.         // Use this for initialization
    8.         void Start ()
    9.         {
    10.      
    11.          }
    12.     }
    13.  
    14. public static class IListExtensions {
    15.      
    16.        public static void Shuffle<T>(this IList<T> ts) {
    17.           var count = ts.Count;
    18.           var last = count - 1;
    19.          for (var i = 0; i < last; ++i) {
    20.              var r = UnityEngine.Random.Range(i, count);
    21.              var tmp = ts[i];
    22.              ts[i] = ts[r];
    23.              ts[r] = tmp;
    24.      
    25.          }
    26.      
    27.        }
    28. }
    29.  
     
  3. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    953
    Believe it or not, classes can legally be nested within the namespaces of other classes:
    http://msdn.microsoft.com/en-gb/library/ms173120.aspx

    This compilation error is occurring because the OP has attempted to place a class within a method ("Start").

    In this particular scenario that class should really reside within its own .cs file.
     
  4. TheMeanCoder

    TheMeanCoder

    Joined:
    Apr 25, 2014
    Posts:
    15
    I did forget to mention that. I am sure they did not want nested classes as that intention would not be valid.