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

array of Struct Options · View
MaMi
Posted: Monday, January 28, 2008 1:34:08 PM
Rank: มือสมัครเล่น
Groups: Member

Joined: 1/13/2008
Posts: 20
Location: bangkok

คืออยากรู้เรื่องเกี่ยวกับ  array of Struct   ตั้งแต่การประกาศตัวแปร แล้วเวลาเรียกใช้เรียกใช้อย่างไร เช่น การเก็บค่า และ ปริ้นค่า

 

ขอบคุณครับ

paedotnet
Posted: Monday, January 28, 2008 11:13:58 PM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 354
Location: bkk
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
struct TestStruct
{
    private string name;
    private int age;
    public TestStruct(string name, int age)
    {
        this.name = name;
        this.age = age;
    }
    public override string ToString()
    {
        return string.Format("Name is {0} ,Age is {1}", name, age);
    }
}
 class TestCallStruct
{
     static void Main()
    {
        TestStruct[] t = { new TestStruct("Jane", 19), new TestStruct("June", 20), new TestStruct("John", 49) };
        for (int i = 0; i < t.Length; i++)
        {
            Console.WriteLine(t[i]);
        }
        Console.ReadLine();
    }
}

ผลลัพธ์แสดงดังรูป



[With great power comes great responsibility]
MaMi
Posted: Tuesday, January 29, 2008 12:00:13 AM
Rank: มือสมัครเล่น
Groups: Member

Joined: 1/13/2008
Posts: 20
Location: bangkok
ขอบคุณครับ

code ตัวอย่างนี้ เหมือน GENERIC ป่าวครับ
paedotnet
Posted: Tuesday, January 29, 2008 1:07:31 AM

Rank: มือเทพ
Groups: Member

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

ไม่เกี่ยวกับ Generic ครับ



[With great power comes great responsibility]
tada1179
Posted: Saturday, February 23, 2008 3:29:32 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 2/23/2008
Posts: 1

ขอโปรแกรมวิธีการใช้ struct การกำหนดค่าให้กับตัวแปลใน struct ขอบคุณคะ

paedotnet
Posted: Wednesday, February 27, 2008 6:28:49 PM

Rank: มือเทพ
Groups: Member

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

ลองดู  http://www.codetoday.net/Default.aspx?g=posts&t=161 นะครับ



[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