C#>Structer
Struct
Vi kan godt ta den løsningen som er brukt som illustrasjon for Properties og endre klassene til structer:
using System;
using System.Collections.Generic;
using System.Text;
namespace lang3
{
class Program
{
static void Main(string[] args)
{
bil1 minBil = new bil1(123, "min");
Console.WriteLine(minBil.getOwner());
bil2 dinBil = new bil2(123, "din");
Console.WriteLine(dinBil.Owner);
}
}
struct bil1
{
private int regno;
private string owner;
public bil1(int n, string s)
{
regno = n;
owner = s;
}
public string getOwner() { return owner; }
public void setOwner(String s) { owner = s; }
public int getRegNo() { return regno; }
public void setRegNo(int n) { regno = n; }
}
struct bil2
{
private int regno;
private string owner;
public bil2(int n, string s)
{
regno = n;
owner = s;
}
public int RegNo
{
get { return regno; }
set { regno = value; }
}
public string Owner
{
get { return owner; }
set { owner = value; }
}
}
}