.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

การใช้งาน printf ใน C# Options · View
paedotnet
Posted: Saturday, September 06, 2008 11:43:24 AM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 344
Location: bkk

การเรียกใช้งาน คำสั่ง 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]
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by