इस पाठ में

एक-एक मान जोड़ें

शून्य से शुरू करें और जैसे ही आप उस तक पहुँचते हैं प्रत्येक मान जोड़ें।

एक आसान उदाहरण

शुरुआत में2 + 4
नतीजा6
Program.cs
using System;

int total = 0;
total += 2;
total += 4;
Console.WriteLine(total);
आउटपुट
6
विज्ञापन

रोज़मर्रा के उदाहरण

तीन कक्षाएं 5, 2 और 4 किताबें दान करती हैं। पुस्तकालय अपनी अलमारियों पर कितनी किताबें रख सकता है?

शुरुआत में5 + 2 + 4
नतीजा11
Program.cs
using System;

int[] books = new int[] { 5, 2, 4 };
int total = 0;
int i = 0;
while (i < 3) {
    total += books[i];
    i += 1;
}
Console.WriteLine(total);
आउटपुट
11
उदाहरण चलाएँ
टर्मिनल
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson
आधिकारिक गाइड