設一class Myclass1的定義如下所示:
1.在Main() method內建立一個Myclass1的物件myobject1
2.將物件myobject1的資料成員a值設為5, b值設為8
3.計算a+b後設給sum
4.印出a,b,sum的值
(執行結果)
a=5, b=8, sum=13
  • 2009-03-29 11:52:54 補充

    <不能執行請幫我修改,謝謝>

  • 2009-03-29 11:53:11 補充

    class Myclass1
    {
    int a;
    int b;
    int sum;
    }

  • 2009-03-29 11:53:30 補充

    public class Myclass1 Test
    {
    public static void Main(string[] args)
    {
    Myclass1 myobiect1;
    myobiect1 =new Myclass1 ();
    myobiect1.a=5;

  • 2009-03-29 11:53:37 補充

    myobiect1.b=8;
    myobiect1.sum =myobiect1.a+myobiect1.b;
    Console .Write ("a={0}, b={1}, sum={2}\n",myobiect1.a,myobiect1.b,myobiect1.sum);
    }
    }

  • 2009-03-29 11:55:11 補充

    就是以上的程式碼,字數太多,所以我補充ㄌ好多次,請見諒><
    拜託各位大大,幫我修改吧!

 

answer:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

Myclass1 myobject1 = new Myclass1();

myobject1.a = 5;
myobject1.b = 8;
myobject1.sum = myobject1.a + myobject1.b;
Console.Write("a={0}, b={1}, sum={2}\n", myobject1.a,myobject1.b, myobject1.sum);


}
}


class Myclass1
{

public int a;
public int b;
public int sum;

}


}

參考資料 me

    全站熱搜

    mitblog 發表在 痞客邦 留言(0) 人氣()