How to use method in struct with C#

1 Answer

0 votes
using System;

struct Student {
    public int id;
    public string name;

    public Student(int _id, string _name) {
        id = _id;
        name = _name;
    }
    public void Show() {
        Console.WriteLine($"id: {this.id} Name: {this.name}");
    }
}

class Program
{
    static void Main(string[] args)
    {
      Student s = new Student(34678, "Emma");
       
      s.Show();
    }
}

 
 
/*
run:
 
id: 34678 Name: Emma
 
*/

 



answered Dec 15, 2020 by avibootz

Related questions

1 answer 151 views
1 answer 145 views
145 views asked Oct 25, 2022 by avibootz
1 answer 105 views
105 views asked Jun 21, 2024 by avibootz
1 answer 131 views
1 answer 141 views
141 views asked Dec 15, 2020 by avibootz
1 answer 142 views
142 views asked Nov 22, 2020 by avibootz
1 answer 159 views
...