1-) C# - Kapsülleme
form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SınıfOlusturmaVeNesneKavrami
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
araba rb = new araba();
rb.renk = "mavi";
rb.hizi = 160;
rb.motor = 1245.56;
rb.fiyat = 50000;
rb.durum = 's';
rb.YIL = -2016;
rb.MARKASI = "Golf";
label1.Text = rb.renk;
label2.Text = rb.hizi.ToString();
label3.Text = rb.motor.ToString();
label4.Text = rb.fiyat.ToString();
label5.Text = rb.durum.ToString();
label6.Text = rb.YIL.ToString();
label7.Text = rb.MARKASI;
pictureBox1.BackColor = Color.CadetBlue;
}
}
}
araba.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SınıfOlusturmaVeNesneKavrami
{
class araba
{
public string renk;
public int hizi;
public double motor;
public char durum;
public int fiyat;
private int yil;
private string marka;
public int YIL
{
get { return yil; }
set { yil = Math.Abs(value); }// eksi değer girse bile + ya çevirir.
}
public string MARKASI
{
get { return marka; }
set { marka = value.ToUpper(); }// hepsini büyük harfe çevirir.
}
}
}
form1.cs[design]
