2. 2
C# | мессеж/текстхэвлэх (Helloworld програм хэвлэх)
Мессеж/текст эсвэл ямар нэг утга хэвлэх хоёр функц ашигладаг.
1. Console.Write ();
Гарч ирэх үр дүнг дараагийн шинэ мөрөнд оруулахгүйгээр гаралтын төхөөрөмж дээр текст
болон утгуудыг харуулдаг функц.
2. Console.WriteLine();
Текст болон утгуудыг гаралтын төхөөрөмж дээр үзүүлэхдээ үр дүнг дараагийн мөрөнд
оруулдаг.
Мөн хэвлэх текстийн дунд n ашиглан шинэ мөр үүсгэж болно.
Програм:
/*c# текст хэвлэх үндсэн програм*/
using System;
class HelloWorld {
static void Main() {
//print text without inserting new line after the message
Console.Write("Hello World,");
Console.Write("How are you?");
//print new line
Console.WriteLine();
//print text with new line after the message
Console.WriteLine("Hello World");
Console.WriteLine("How are you?");
//print new line using escape sequence just like C language
Console.WriteLine("Hello WorldnHow are you?");
}
}
Гарах үр дүн
Hello World,How are you?
Hello World
How are you?
Hello World
How are you?
3. 3
Console.Write() болон Console.WriteLine()
Console.WriteLine() болон Console.Write()-ийн жишээн дээр харуулах.
Жишээ:
// C# program to demonstrate example of
// Console.Write() and Console.WriteLine()
using System;
using System.IO;
using System.Text;
namespace IncludeHelp
{
class Test
{
// Main Method
static void Main(string[] args)
{
Console.WriteLine("This is line1");
Console.WriteLine("This is line2");
Console.Write("This is line3");
Console.Write("This is line4");
//hit ENTER to exit the program
Console.ReadLine();
}
}
}
Гарах үр дүн
This is line1
This is line2
This is line3This is line4
4. 4
Шинэ мөрөнд хэвлэх
n
x0A эсвэл xA
Console.WriteLine()
Жишээ:
// C# program to print a new line
using System;
using System.IO;
using System.Text;
namespace IncludeHelp
{
class Test
{
// Main Method
static void Main(string[] args)
{
//using n
Console.WriteLine("HellonWorld");
//using x0A
Console.WriteLine("Hellox0AWorld");
Console.WriteLine();
Console.WriteLine("end of the program");
//hit ENTER to exit the program
Console.ReadLine();
}
}
}
Гарах үр дүн
Hello
World
Hello
World
end of the program
Бие даажгүйцэтгэх бодлогууд:
1.4. Тэгш өнцөгтийн а, b талууд өгөгдсөнбол приметр болонталбайг ол.
1.5. Тойргийн радиус өгөгдсөн ба талбай,тойргийн уртыг ол.
1.6. 1-ээс 20 хүртэлх тоонуудын нийлбэрийг унар, бинар үйлдэл ашиглан гүйцэтгээрэй.