小编Hz *_*ang的帖子

这些代码在c#的内存中是否安全?

我对以下代码有疑问.

首先,这些代码运作良好.

但是,没有关于Student类中"课程"的定义的声明.如果在Student的构造函数中,参数是常量,这些代码是否安全?谢谢你的帮助!:)

public class Student
{
    public string name;
    public int age;
    public string[] courses;
    public Student(string _name, int _age,params string[] _courses)
    {
        name = _name;
        age = _age;

        courses = _courses;//is this OK if _courses is constant?


    }
}
public class work : MonoBehaviour 
{
    void Start()
    {
       /*
        string[] courses={"math", "English"};
        Student Tom = new Student("Tom",18,courses);
        //It's wrong!
       */
        Student Tom = new Student("Tom", 18, "math", "English");
        string Tom_text = JsonUtility.ToJson(Tom);
        Debug.Log(Tom_text);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

3
推荐指数
1
解决办法
77
查看次数

标签 统计

c# ×1

unity-game-engine ×1