【问题标题】:What does the (); represent in C#?What does the (); represent in C#?
【发布时间】:2022-12-27 09:39:18
【问题描述】:

so we have received a bunch of code from our teacher without him really explaining some of the functions behind it, so I have a silly question - Please be gentle.

I have an array of customers called customerlist and a for loop to load some text written in a document using StreamReader like so.

        customer[] customerlist = new customer[0];

        for (int i = 0; i < customerlist.Length; i++)
        {
            customerlist[i] = new customer();
            customerlist[i].id = Convert.ToInt32(reader.ReadLine());
            customerlist[i].FullName = reader.ReadLine();
        }

I know that the second and third lines of the for loop will read the customer id and full name though I am struggling to understand the functionality of the first line that is customerlist[i] = new customer(); and specifically the purpose of new customer(); I know that i might now have been very clear but hopefully someone could help me out a little, give me a hint of what that specific line of code id used for new customer(); Thanks.

【问题讨论】:

  • That's called aconstructorexpression. Itinstantiates(creates) a new instance of the customer type

标签: c# arrays streamreader


【解决方案1】:

In C# and Java thenewkeyword means a creation of a object of a class.

The "()" say what you have before is a function.

【讨论】:

    猜你喜欢
    • 2022-12-02
    • 2022-12-02
    • 2022-12-02
    • 2022-12-02
    • 2022-12-15
    • 1970-01-01
    • 2022-12-02
    • 2022-12-27
    • 2022-12-01
    相关资源
    最近更新 更多