From 1b1162c5ca8a2d7d446c4f3cfcd00747958d972e Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Mon, 10 Feb 2025 16:01:45 +0700 Subject: [PATCH 01/15] Add: program basic part. 1 --- Program.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Program.cs b/Program.cs index fd851a1..034bbd9 100644 --- a/Program.cs +++ b/Program.cs @@ -4,10 +4,15 @@ class Program { static void Main() { + // Output to console basic text Console.WriteLine("Hello World!"); - // See https://aka.ms/new-console-template for more information - Console.WriteLine("Hello, World!"); - var name = Console.ReadLine(); + + // Output get datetime to console Console.WriteLine("Date now: " + DateTime.Now); + + // Input from user + var name = Console.ReadLine(); + // Output to console + Console.WriteLine("Hi, " + name); } } \ No newline at end of file From bc78c3ed149245b7053092e6433907d152808a50 Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Mon, 10 Feb 2025 16:31:37 +0700 Subject: [PATCH 02/15] Update: program, modify output --- Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Program.cs b/Program.cs index 034bbd9..e368e44 100644 --- a/Program.cs +++ b/Program.cs @@ -11,6 +11,7 @@ static void Main() Console.WriteLine("Date now: " + DateTime.Now); // Input from user + Console.Write("Type your name: "); var name = Console.ReadLine(); // Output to console Console.WriteLine("Hi, " + name); From 3fb9e1baff392982c18803a2e0dcfaa32bdcf893 Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Mon, 10 Feb 2025 17:08:19 +0700 Subject: [PATCH 03/15] Update: program.cs add function to call in Main --- Program.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index e368e44..60c0e2c 100644 --- a/Program.cs +++ b/Program.cs @@ -5,15 +5,27 @@ class Program static void Main() { // Output to console basic text - Console.WriteLine("Hello World!"); + // Console.WriteLine(TextHello()); // Output get datetime to console - Console.WriteLine("Date now: " + DateTime.Now); + // Console.WriteLine(GetDateSystem()); // Input from user + Console.WriteLine(InputFromUser()); + } + + static String TextHello() { + return "Hello World!"; + } + + static String GetDateSystem() { + DateTime getDateBySystem = DateTime.Now; + return "Date now: " + getDateBySystem; + } + + static String InputFromUser() { Console.Write("Type your name: "); var name = Console.ReadLine(); - // Output to console - Console.WriteLine("Hi, " + name); + return "Hi, " + name; } } \ No newline at end of file From 6e44086a80d15224eaab9e88716a755bdff04917 Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Mon, 10 Feb 2025 17:08:27 +0700 Subject: [PATCH 04/15] Add: README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b2d1b46 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +## Project Base Learn .NET Console +Project console .NET basic from 0 to hero + +## a. Get Date by System + +```.cs +Console.WriteLine("Date now: " + DateTime.Now); +``` + +## b. Type Input & Show to Output + +```.cs +Console.Write("Type your name: "); +var name = Console.ReadLine(); +Console.WriteLine("Hi, " + name); +``` \ No newline at end of file From 1595e4ee98f33c78065b371936f115aa18eb8426 Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Tue, 11 Feb 2025 23:51:21 +0700 Subject: [PATCH 05/15] Add: Store, Retrieve Data using Literal & Variable Value --- Program.cs | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Program.cs b/Program.cs index 60c0e2c..5f40e70 100644 --- a/Program.cs +++ b/Program.cs @@ -4,28 +4,33 @@ class Program { static void Main() { - // Output to console basic text - // Console.WriteLine(TextHello()); - - // Output get datetime to console - // Console.WriteLine(GetDateSystem()); - - // Input from user - Console.WriteLine(InputFromUser()); + // Call the Function method Type here + ThirdStage(); } - static String TextHello() { - return "Hello World!"; + static void FirstStage() { + string name = "Bob"; + int value = 3; + float temperature = 34.4f; + + Console.WriteLine($"Hello, {name}! You have {value} messages in your inbox. The temperature is {temperature} celsius."); } - static String GetDateSystem() { - DateTime getDateBySystem = DateTime.Now; - return "Date now: " + getDateBySystem; + static void SecondStage() { + decimal value = 3.14159265359m; + double radius = 2.5323; + + Console.WriteLine($"The value of Pi is approximately {value}."); + Console.WriteLine($"The radius of the circle is {radius}."); } - static String InputFromUser() { - Console.Write("Type your name: "); - var name = Console.ReadLine(); - return "Hi, " + name; + static void ThirdStage() { + bool isStatus = false; + int age = 20; + if (age >= 18) { + isStatus = true; + } + + Console.WriteLine($"Is the person {age} years old, an adult? {isStatus}"); } } \ No newline at end of file From 805dc69796bf6cd5e60402ea98550c9207743670 Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Tue, 11 Feb 2025 23:51:32 +0700 Subject: [PATCH 06/15] Update: README.md --- README.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b2d1b46..df5622d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,30 @@ ## Project Base Learn .NET Console Project console .NET basic from 0 to hero -## a. Get Date by System +## a. Store, Retrieve Data using Literal & Variable Value ```.cs -Console.WriteLine("Date now: " + DateTime.Now); +string name = "Bob"; +int value = 3; +float temperature = 34.4f; + +Console.WriteLine($"Hello, {name}! You have {value} messages in your inbox. The temperature is {temperature} celsius."); ``` -## b. Type Input & Show to Output +```.cs +decimal value = 3.14159265359m; +double radius = 2.5323; + +Console.WriteLine($"The value of Pi is approximately {value}."); +Console.WriteLine($"The radius of the circle is {radius}."); +``` ```.cs -Console.Write("Type your name: "); -var name = Console.ReadLine(); -Console.WriteLine("Hi, " + name); +bool isStatus = false; +int age = 20; +if (age >= 18) { + isStatus = true; +} + +Console.WriteLine($"Is the person {age} years old, an adult? {isStatus}"); ``` \ No newline at end of file From 538e8caee0dc4e5ceda9df6eb334a8e07362f301 Mon Sep 17 00:00:00 2001 From: Asep Septiadi <98740335+aspsptyd@users.noreply.github.com> Date: Tue, 11 Feb 2025 23:55:48 +0700 Subject: [PATCH 07/15] Update: adding image result of code --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df5622d..e4d7af6 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ float temperature = 34.4f; Console.WriteLine($"Hello, {name}! You have {value} messages in your inbox. The temperature is {temperature} celsius."); ``` +![Screenshot 2025-02-11 at 23 54 13](https://github.com/user-attachments/assets/13be9a34-0abc-4e8e-b0e5-e3813e5557fb) + + ```.cs decimal value = 3.14159265359m; double radius = 2.5323; @@ -19,6 +22,9 @@ Console.WriteLine($"The value of Pi is approximately {value}."); Console.WriteLine($"The radius of the circle is {radius}."); ``` +![Screenshot 2025-02-11 at 23 54 49](https://github.com/user-attachments/assets/db3b66de-2428-4e46-8229-911b6b5ff2a8) + + ```.cs bool isStatus = false; int age = 20; @@ -27,4 +33,6 @@ if (age >= 18) { } Console.WriteLine($"Is the person {age} years old, an adult? {isStatus}"); -``` \ No newline at end of file +``` + +![Screenshot 2025-02-11 at 23 55 12](https://github.com/user-attachments/assets/ea41a4f1-55f6-4133-b6b0-4f859ed74ba5) From 84567846faff44de480763734ff58ab752442a3f Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Wed, 12 Feb 2025 00:25:40 +0700 Subject: [PATCH 08/15] Add: Format Literal String --- Program.cs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/Program.cs b/Program.cs index 5f40e70..df99547 100644 --- a/Program.cs +++ b/Program.cs @@ -9,28 +9,19 @@ static void Main() } static void FirstStage() { - string name = "Bob"; - int value = 3; - float temperature = 34.4f; - - Console.WriteLine($"Hello, {name}! You have {value} messages in your inbox. The temperature is {temperature} celsius."); + Console.WriteLine("Hello\nWorld!"); + Console.WriteLine("Hello\tWorld!"); } static void SecondStage() { - decimal value = 3.14159265359m; - double radius = 2.5323; - - Console.WriteLine($"The value of Pi is approximately {value}."); - Console.WriteLine($"The radius of the circle is {radius}."); + Console.WriteLine("Generating invoices for customer \"Contoso Corp\" ... \n"); + Console.WriteLine("Invoice: 1021\t\tComplete!"); + Console.WriteLine("Invoice: 1022\t\tComplete!"); + Console.WriteLine("\nOutput Directory:\t"); } static void ThirdStage() { - bool isStatus = false; - int age = 20; - if (age >= 18) { - isStatus = true; - } - - Console.WriteLine($"Is the person {age} years old, an adult? {isStatus}"); + Console.WriteLine(@" c:\source\repos + (this is where your code goes)"); } } \ No newline at end of file From 5a923b0c294982a61e459fc54ec0e1a5edc4b361 Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Wed, 12 Feb 2025 00:25:46 +0700 Subject: [PATCH 09/15] Update: README.md --- README.md | 67 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e4d7af6..9ce715d 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,65 @@ ## Project Base Learn .NET Console Project console .NET basic from 0 to hero -## a. Store, Retrieve Data using Literal & Variable Value +## a. Format Literal String - Character escape sequences +Urutan karakter escape adalah instruksi ke runtime untuk menyisipkan karakter khusus yang akan memengaruhi output string Anda. Dalam C#, urutan karakter escape dimulai dengan garis miring \ terbalik diikuti oleh karakter yang Anda kabur. Misalnya, urutan \n akan menambahkan baris baru, dan urutan \t akan menambahkan tab. ```.cs -string name = "Bob"; -int value = 3; -float temperature = 34.4f; - -Console.WriteLine($"Hello, {name}! You have {value} messages in your inbox. The temperature is {temperature} celsius."); +Console.WriteLine("Hello\nWorld!"); +Console.WriteLine("Hello\tWorld!"); ``` -![Screenshot 2025-02-11 at 23 54 13](https://github.com/user-attachments/assets/13be9a34-0abc-4e8e-b0e5-e3813e5557fb) +Jika ekspektasi yang ingin kita tampilkan seperti `Hello "World"!` maka eksekusi programnya +Bukan seperti dibawah `X` ```.cs -decimal value = 3.14159265359m; -double radius = 2.5323; +Console.WriteLine("Hello "World"!"); +``` +Tapi menangani situasi tersebut \" , gunakan urutan escape, yaitu seperti berikut `√` +```.cs +Console.WriteLine("Hello \"World\"!"); +``` +Lalu jika Anda perlu menggunakan garis miring terbalik untuk tujuan lain, seperti menampilkan jalur file? gunakan karakter seperti berikut +```.cs +Console.WriteLine("c:\\source\\repos"); +``` +Ekspektasi output adalah `c:\source\repos`, lalu dibawah ini kita ingin membuat output seperti berikut +```.sh +Generating invoices for customer "Contoso Corp" ... + +Invoice: 1021 Complete! +Invoice: 1022 Complete! -Console.WriteLine($"The value of Pi is approximately {value}."); -Console.WriteLine($"The radius of the circle is {radius}."); +Output Directory: ``` +Ekseksui programnya adalah sebagai berikut +```.cs +Console.WriteLine("Generating invoices for customer \"Contoso Corp\" ... \n"); +Console.WriteLine("Invoice: 1021\t\tComplete!"); +Console.WriteLine("Invoice: 1022\t\tComplete!"); +Console.WriteLine("\nOutput Directory:\t"); +``` +## b. Format Literal String - Verbatim string literal +Akan menyimpan semua spasi kosong dan karakter tanpa perlu menghindari garis miring terbalik. Untuk membuat string verbatim, gunakan arahan `@` sebelum string literal. +```.cs +Console.WriteLine(@" c:\source\repos + (this is where your code goes)"); +``` +## c. Format Literal String - Unicode escape characters +Anda juga dapat menambahkan karakter yang dikodekan dalam string harfiah menggunakan urutan escape \u, lalu kode empat karakter yang mewakili beberapa karakter dalam Unicode (UTF-16). -![Screenshot 2025-02-11 at 23 54 49](https://github.com/user-attachments/assets/db3b66de-2428-4e46-8229-911b6b5ff2a8) +Untuk melihat di online bisa cek di website https://symbl.cc/en/unicode-table/ +Contoh implementasi ```.cs -bool isStatus = false; -int age = 20; -if (age >= 18) { - isStatus = true; -} - -Console.WriteLine($"Is the person {age} years old, an adult? {isStatus}"); +Console.WriteLine("\u3053\u3093\u306B\u3061\u306F World!"); ``` +Output `こんにちは World!` + +Jika kita merujuk pada laman online site diatas kita ingin menampilkan tanda `*` dengan karakter unicode kita gunakan code program berikut -![Screenshot 2025-02-11 at 23 55 12](https://github.com/user-attachments/assets/ea41a4f1-55f6-4133-b6b0-4f859ed74ba5) +```.cs +Console.WriteLine("\u002A"); +``` \ No newline at end of file From 57edf32994d8e5776418500f78d918214bfff0cc Mon Sep 17 00:00:00 2001 From: Asep Septiadi <98740335+aspsptyd@users.noreply.github.com> Date: Wed, 12 Feb 2025 00:28:16 +0700 Subject: [PATCH 10/15] Update: add image --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ce715d..8383395 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ Output `こんにちは World!` Jika kita merujuk pada laman online site diatas kita ingin menampilkan tanda `*` dengan karakter unicode kita gunakan code program berikut +![Screenshot 2025-02-12 at 00 27 26](https://github.com/user-attachments/assets/f2c51584-382f-4e9c-a5a6-b1a15e668f71) + ```.cs Console.WriteLine("\u002A"); -``` \ No newline at end of file +``` From 1358dcdb9b6beba994f18a916e83cf206a59ef0e Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Wed, 12 Feb 2025 00:40:44 +0700 Subject: [PATCH 11/15] Add: Combine strings using string concatenation --- Program.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index df99547..2473eab 100644 --- a/Program.cs +++ b/Program.cs @@ -5,7 +5,7 @@ class Program static void Main() { // Call the Function method Type here - ThirdStage(); + FourthStage(); } static void FirstStage() { @@ -24,4 +24,16 @@ static void ThirdStage() { Console.WriteLine(@" c:\source\repos (this is where your code goes)"); } + + static void FourthStage() { + string firstName = "Bob"; + string message = "Hello " + firstName; + Console.WriteLine(message); + + string greeting = "Hello"; + string messagenew = greeting + " " + firstName + "!"; + Console.WriteLine(messagenew); + + Console.WriteLine(greeting + " " + firstName + "!"); + } } \ No newline at end of file From 1ece416d27aee7a9d1b88dcfd9ba5403cc9f294f Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Wed, 12 Feb 2025 00:40:57 +0700 Subject: [PATCH 12/15] Update: README.md adding content --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 8383395..cc08bb5 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,37 @@ Jika kita merujuk pada laman online site diatas kita ingin menampilkan tanda `*` ```.cs Console.WriteLine("\u002A"); ``` +## d. Combine strings using string concatenation +Sering kali, Anda harus menggabungkan data dari berbagai sumber, termasuk string harfiah dan variabel yang berisi data teks dan numerik. Di pelajaran ini, Anda akan menggunakan perangkaian string untuk menggabungkan dua atau lebih nilai menjadi string baru. + +Sederhananya misal menggabungkan kata `Rumah Makan` rangkaian 2 kata dijadikan 1 `Rumah` dan `Makan` + +String concatenationadalah "programmer speak" hanya untuk menggabungkan dua nilai atau lebih string ke dalam nilai baru string . Tidak seperti penambahan, nilai kedua ditambahkan ke akhir nilai pertama, dan seterusnya. Dalam latihan berikut, Anda akan menulis kode untuk menggabungkan string nilai bersama-sama. + +### 1. Menggabungkan string literal dan variabel +Untuk menggabungkan dua string, Anda menggunakan operator perangkaian string, yang merupakan simbol plus `+` + +```.cs +string firstName = "Bob"; +string message = "Hello " + firstName; +Console.WriteLine(message); +``` +Perhatikan urutannya—string "Hello " pertama berada di string baru, dan nilai dalam firstName variabel ditambahkan ke akhir. + +### 2. Concatenate multiple variables and literal strings +Anda dapat melakukan beberapa operasi perangkaian dalam baris kode yang sama. Di sini Anda membuat pesan yang lebih kompleks dengan menggabungkan beberapa variabel dan string literal. + +```.cs +string firstName = "Bob"; +string greeting = "Hello"; +string message = greeting + " " + firstName + "!"; +Console.WriteLine(message); +``` + +### 3. Avoiding intermediate variables +Pada langkah-langkah sebelumnya, Anda menggunakan variabel tambahan untuk menahan string baru yang dihasilkan dari operasi perangkaian (concatenation). Kecuali Anda memiliki alasan yang baik untuk melakukannya, Anda dapat (dan harus) menghindari penggunaan variabel perantara dengan melakukan operasi perangkaian sesuai kebutuhan. + +```.cs +Console.WriteLine(greeting + " " + firstName + "!"); +``` +Output tetap sama sebenarnya \ No newline at end of file From 60fde0e193a0532acbdd322fdda580d56c21fcc5 Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Wed, 12 Feb 2025 00:45:49 +0700 Subject: [PATCH 13/15] Update: README.md update dan merge content --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cc08bb5..553ae1d 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Jika kita merujuk pada laman online site diatas kita ingin menampilkan tanda `*` ```.cs Console.WriteLine("\u002A"); +<<<<<<< Updated upstream ``` ## d. Combine strings using string concatenation Sering kali, Anda harus menggabungkan data dari berbagai sumber, termasuk string harfiah dan variabel yang berisi data teks dan numerik. Di pelajaran ini, Anda akan menggunakan perangkaian string untuk menggabungkan dua atau lebih nilai menjadi string baru. @@ -98,4 +99,7 @@ Pada langkah-langkah sebelumnya, Anda menggunakan variabel tambahan untuk menaha ```.cs Console.WriteLine(greeting + " " + firstName + "!"); ``` -Output tetap sama sebenarnya \ No newline at end of file +Output tetap sama sebenarnya +======= +``` +>>>>>>> Stashed changes From 9d6fd79f0cc4e142961dc07c4b4a99491f9102ab Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Wed, 12 Feb 2025 00:46:44 +0700 Subject: [PATCH 14/15] Perbaiki merge --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 553ae1d..e62f5ff 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,6 @@ Jika kita merujuk pada laman online site diatas kita ingin menampilkan tanda `*` ```.cs Console.WriteLine("\u002A"); -<<<<<<< Updated upstream ``` ## d. Combine strings using string concatenation Sering kali, Anda harus menggabungkan data dari berbagai sumber, termasuk string harfiah dan variabel yang berisi data teks dan numerik. Di pelajaran ini, Anda akan menggunakan perangkaian string untuk menggabungkan dua atau lebih nilai menjadi string baru. @@ -100,6 +99,3 @@ Pada langkah-langkah sebelumnya, Anda menggunakan variabel tambahan untuk menaha Console.WriteLine(greeting + " " + firstName + "!"); ``` Output tetap sama sebenarnya -======= -``` ->>>>>>> Stashed changes From d0b52d89c67a2ab99794e7653a1b170c840c83eb Mon Sep 17 00:00:00 2001 From: aspsptyd Date: Wed, 12 Feb 2025 01:12:25 +0700 Subject: [PATCH 15/15] Update: README.md some content --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index e62f5ff..20ed19b 100644 --- a/README.md +++ b/README.md @@ -99,3 +99,59 @@ Pada langkah-langkah sebelumnya, Anda menggunakan variabel tambahan untuk menaha Console.WriteLine(greeting + " " + firstName + "!"); ``` Output tetap sama sebenarnya +## e. Combine strings using string interpolation +Meskipun perangkaian string sederhana dan mudah dilakukan, interpolasi string menjadi lebih populer dalam situasi saat Anda perlu menggabungkan banyak string literal dan variabel ke dalam satu pesan yang diformat. + +Ianya menggabungkan beberapa nilai menjadi string literal tunggal dengan menggunakan "templat" dan satu atau beberapa ekspresi interpolasi. Ekspresi interpolasi ditunjukkan oleh simbol `{ }` kurung kurawal pembuka dan penutupan kurung kurawal. Anda dapat menempatkan ekspresi C# apa pun yang mengembalikan nilai di dalam kurung kurawal. String literal menjadi templat saat diawali oleh karakter `$`. + +Daripada menuliskan code program + +```.cs +string message = greeting + " " + firstName + "!"; +``` +lebih baik seperti berikut +```.cs +string message = $"{greeting} {firstName}!"; +``` +Dalam contoh sederhana ini, Anda menghemat beberapa tombol untuk ditekan. Anda dapat membayangkan berapa banyak interpolasi string yang lebih ringkas berada dalam operasi yang lebih kompleks. Selain itu, banyak yang berpikir bahwa sintaks interpolasi string lebih rapi dan mudah dibaca. + +### 1. Use string interpolation to combine a literal string and a variable value +Untuk menginterpolasi dua string bersama-sama, Anda membuat string literal dan mengawali string dengan simbol `$`. String harfiah harus berisi setidaknya satu set kurung kurawal `{}` dan di dalam karakter tersebut, Anda menggunakan nama variabel. + +```.cs +string firstName = "Bob"; +string message = $"Hello {firstName}!"; +Console.WriteLine(message); +``` +Secara output sebenarnya sama saja seperti definisi sebelum pembahasan ini, namun lebih ringkas + +### 2. Use string interpolation with multiple variables and literal strings +Anda dapat melakukan beberapa operasi interpolasi di baris kode yang sama. + +```.cs +int version = 11; +string updateText = "Update to Windows"; +string message = $"{updateText} {version}"; +Console.WriteLine(message); +``` +Output `Update to Windows 11` + +### 3. Avoid intermediate variables +Sama seperti yang Anda lakukan di latihan sebelumnya, Anda dapat menghilangkan variabel sementara untuk menyimpan pesan. + +```.cs +int version = 11; +string updateText = "Update to Windows"; +Console.WriteLine($"{updateText} {version}!"); +``` +Output `Update to Windows 11` + +### 4. Combine verbatim literals and string interpolation +Misalkan Anda perlu menggunakan literal verbatim dalam templat. Anda dapat menggunakan simbol awalan literal verbatim `@` dan simbol interpolasi string `$` bersama-sama. + +```.cs +string projectName = "First-Project"; +Console.WriteLine($@"C:\Output\{projectName}\Data"); +``` +Output `C:\Output\First-Project\Data` +Dalam contoh ini, `$` simbol memungkinkan Anda untuk mereferensikan `projectName` variabel di dalam kurung kurawal, sementara `@` simbol memungkinkan Anda untuk menggunakan karakter yang tidak dilewati `\`. \ No newline at end of file