Passing variables from Main function to another C# class

前端 未结 4 622
轮回少年
轮回少年 2021-01-21 07:56

I\'m beating my head against the wall pretty severely with this. I have several variables inside a C# console application that I would like to re-use. However, I cannot for th

4条回答
  •  感情败类
    2021-01-21 08:32

    you should define public property or public field

    public class Student
    {
    public string Name {get;set;}
    }
    

    and when you want to pass value you can assign this value to property

    Student st = new Student(); 
    st.Name = "your value";
    

    or you can use class constructor too.

提交回复
热议问题