CSharp examples for Custom Type:Field
Put methods that operate on a class's data inside the class.
using System;//from www . j ava2 s .c o m public class Student { public string name; public static void OutputName(Student student) { Console.WriteLine("Student's name is {0}", student.name); } public static void SetName(Student student, string name) { student.name = name; } } public class Program { public static void Main(string[] args) { Student student = new Student(); student.name = "Madeleine"; Student.OutputName(student); // Method now belongs to Student. Student.SetName(student, "new"); Student.OutputName(student); } }