-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetSetMethods2.cs
62 lines (52 loc) · 1.84 KB
/
GetSetMethods2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
namespace ConsoleApp
{
class Book
{
// Özel alanlar (fields)
private string title; // Kitap adı
private string author; // Yazar adı
// Getter metodu: 'title' alanının değerini döndürür
public string GetTitle()
{
return title;
}
// Setter metodu: 'title' alanına bir değer atar
public void SetTitle(string newTitle)
{
title = newTitle;
}
// Getter metodu: 'author' alanının değerini döndürür
public string GetAuthor()
{
return author;
}
// Setter metodu: 'author' alanına bir değer atar
public void SetAuthor(string newAuthor)
{
author = newAuthor;
}
}
class Program
{
static void Main(string[] args)
{
// Book sınıfından bir nesne oluşturuyoruz
Book myBook = new Book();
// Başlangıç değerlerini yazdırıyoruz (null olacaktır)
Console.WriteLine($"Initial title is: {myBook.GetTitle()}");
Console.WriteLine($"Initial author is: {myBook.GetAuthor()}");
// Kullanıcıdan kitap adını alıyoruz
Console.WriteLine("Enter the book title: ");
string bookTitle = Console.ReadLine();
myBook.SetTitle(bookTitle);
// Kullanıcıdan yazar adını alıyoruz
Console.WriteLine("Enter the author's name: ");
string bookAuthor = Console.ReadLine();
myBook.SetAuthor(bookAuthor);
// Girilen değerleri yazdırıyoruz
Console.WriteLine($"The book title is: {myBook.GetTitle()}");
Console.WriteLine($"The author is: {myBook.GetAuthor()}");
}
}
}