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

เพิ่งลองมาเขียน ASP.net แล้ว เพิ่งใช่ C# เลยลองเขียน ในการคำนวนดู ช่วยมาดูหน่อยครับ Options · View
Hi_nok
Posted: Friday, March 14, 2008 8:38:28 PM
Rank: มือสมัครเล่น
Groups: Member

Joined: 3/6/2008
Posts: 11
Location: thai
byte x = convert.tobyte(textbox1.text);
byte y = convert.tobyte(textbox2.text);
byte z = (byte)(x+y);
label1.text=convert.tostring(z);

 

คือ มี textbox1 , textbox2     label1  และมี ปุ่ม 1 ปุ่ม
code เป็นยังงี้ อ่ะครับ นี้ ก็ใช่เวลาทำความเข้าใจ ตั้ง 3 วันเลย พอดีรู้สึกมันยาวไป พอมีวิธีเขียนที่กระชับกว่านี้ป่ะครับ พอดีดูหนังสือแล้ว งง ส่วน code VB6 มัน เขียน 1 บรรทัดเอง
label1.caption = val(text1.text)+val(text2.text) ช่วยหน่อยนะครับ อยากศึกษา c#  แฮะ ๆ แค่ คำนวนก็ดูตังนานและ
   ขอบคุณครับ

mrxc
Posted: Saturday, March 15, 2008 6:02:32 AM
Rank: มือเทพ
Groups: Member

Joined: 3/6/2008
Posts: 196
Location: TH

ก็ได้นี้ครับ แต่ไม่มีความจำเป็นต้องเป็น byte หรอกครับผมว่า Float, Int ไปเลยดีกว่าครับ

int result = int.Parse(texbox1.text) + int.Parse(textbox2.text);

ได้เลยครับ

Parse คือ Method ในการถอดตัวเลขจาก String จะเป็นการใช้ได้ดีกว่าการใช้ convert.To...... ต่างๆครับ

Hi_nok
Posted: Saturday, March 15, 2008 1:57:40 PM
Rank: มือสมัครเล่น
Groups: Member

Joined: 3/6/2008
Posts: 11
Location: thai

ขอบคุณครับ พอดีเพิ่งลองดู ดูหนังสือ ง ง

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