การเรียกใช้งาน คำสั่ง printf ใน C#
ถ้าใครเคยเขียนภาษา c มาก่อน จะเห็นว่า คำสั่ง printf จะใช้ในการแสดงข้อมูลหรือพิมพ์ข้อมูลต่างๆออกทางจอภาพดังนั้น
ใน C# ก็ทำให้แต่ว่าไม่สามารถเขียนได้โดยตรงๆเหมือน C แต่จะต้องมีการ import dll เข้าโดย dll ที่ต้อง Import เข้ามาก็คือ
msvcrt
ตัวอย่างโค้ดสำหรับการใช้งาน printf
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int i = 10;
int j = 20;
CallMSVCRT.printf("(%d + %d) = %d\n", i, j, i + j);
}
}
class CallMSVCRT
{
[DllImport("msvcrt.dll")]
public static extern int printf(string format, int lhs, int rhs, int total);
}
}

[With great power comes great responsibility]