| |

VerySource

 Forgot password?
 Register
Search
View: 691|Reply: 5

I am a beginner and would like to ask a question about the structure types of C #.

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-5 17:10:01
| Show all posts |Read mode
using System;

struct phonebook1

{
public string name;

public string phone;

public uint age;

struct address

{

public string city;

public string street;

public uint no;

}

}
class test

{
public static void Main ()

{


phonebook1 p1;

p1.name = "Little Red";

p1.phone = "1234567";

p1.age = 26;

Console.WriteLine ("Name: {0}, Phone: {1}, Age: {2}!", P1.name, p1.phone, p1.age);

}

}

Q: How do I assign values ​​to members in address?

Thank you
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 00:27:01
| Show all posts
p1.address.city = "newyork";
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 02:33:01
| Show all posts
Sorry, it seems I can't do it.
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 South Africa

Post time: 2020-1-6 03:09:01
| Show all posts
Nesting a type in this type is not a good design.
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-1-6 06:57:01
| Show all posts
It is recommended to use class design. I saw a sentence that in C #, designing a structure as a class is much less harmful than designing a class as a structure.
So it is recommended that the landlord use class implementation to try
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-6 08:48:01
| Show all posts
Thank you brothers, I will try to learn.

Thanks in advance!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list