Discussion:
構造体のインデックスのプロパティとは何でしょう?
(too old to reply)
AnswerSoft(M.Fudano)
2005-01-13 05:53:50 UTC
Permalink
$B$3$s$K$A$O!"(B!(^^)!$B$U!A$G$9!#(B

C#$B9=B$BN$r??LLL\$K5-=R$K$O$I$&$9$k$N$+$J$!$HJY6/Cf$G$9!#(B
$B$J$s$H!"!V(BC++$B!W$+$iHf$Y$k$H?oJ,3HD%$5$l$?$b$N$G$9!#$$$D$b$O!"(B
$B0lIt$N5!G=$7$+;H$C$F$J$$!#$HH?>J$G$9!#(B

$B$=$l$G!"%5%s%W%k:***@.!#$H$3$m$,!"%&%)%C%A$G!V(BTom$B!W(B
$B$r8+$^$9$H!"(BItem <$B%$%s%G%C%/%9$N%W%m%Q%F%#$rI=<($G$-$^$;$s(B>
$B$J$I$H$"$k$N$G$9$,!"M=$a!"%*%V%8%'%/%H$+2?=h$+$KDj5A$,$"$k$N$G$7$g$&!#(B
$B$7$+$7!"$H$F$b5$$K$J$j$^$9!#!!2?$G$7$g$&$3$l$O!)!!(BItem$B$rDj5A$7$F(B
$B$3$N%a%C%;!<%8$r>C$7$?$$$N$G$9$,$I$&$9$k$N$G$7$g$&$+!)!!$465<x$*4j$$CW$7$^$9!#(B

$B!V%3%s%=!<%k%"%W%j%1!<%7%g%sMQ!W(B
using System;

namespace ConsoleApplicationTest1
{
struct DATA1
{
public const int MaxData = 10;
public int Number;
private static int[] $B!!(B Array;

// Static Initialization
static DATA1()
{
Array = new int[MaxData];
}

// Index creation
public int this[int index]
{
get
{
// Check the index limits.
if (index < 0 || index >= MaxData)
return 0;
else
return Array[index];
}
set
{
// Check the index limits.
if (0 < index && index < MaxData)
Array[index] = value;
}
}

// Override the ToString method:
public override string ToString()
{
return(String.Format("(MaxData={0},Number={1})", MaxData, Number));
}
}

/// <summary>
/// Class1 $B$N35MW$***@bL@$G$9!#(B
/// </summary>
class Class1
{
/// <summary>
/// $B%"%W%j%1!<%7%g%s$N%a%$%s(B $B%(%s%H%j(B $B%]%$%s%H$G$9!#(B
/// </summary>
[STAThread]
static void Main(string[] args)
{
int no;
//$BKt$O!"(BDATA1 Tom = new DATA1();
DATA1 Tom;

// $B%G!<%?3JG<=hM}(B
Tom.Number = DATA1.MaxData;
for( no = 0; no < Tom.Number ; no++ ) Tom[no] = no;

//$B!!I=<(=hM}(B
Console.WriteLine( Tom );
for( no = 0; no < Tom.Number ; no++ )
{
Console.Write(Tom[no]);
if(no != Tom.Number-1) Console.Write(", ");
}
Console.Write("\n");
}
}
}
Kaoru Kodaka
2005-01-13 07:42:19 UTC
Permalink
$B$+$*$/(B $B$G$9!#(B

On Thu, 13 Jan 2005 14:53:50 +0900
Post by AnswerSoft(M.Fudano)
$B$r8+$^$9$H!"(BItem <$B%$%s%G%C%/%9$N%W%m%Q%F%#$rI=<($G$-$^$;$s(B>
$B$J$I$H$"$k$N$G$9$,!"M=$a!"%*%V%8%'%/%H$+2?=h$+$KDj5A$,$"$k$N$G$7$g$&!#(B
$B$7$+$7!"$H$F$b5$$K$J$j$^$9!#!!2?$G$7$g$&$3$l$O!)!!(BItem$B$rDj5A$7$F(B
$B$3$N%a%C%;!<%8$r>C$7$?$$$N$G$9$,$I$&$9$k$N$G$7$g$&$+!)!!$465<x$*4j$$CW$7$^$9!#(B
http://www.microsoft.com/japan/msdn/library/default.asp?url=/japan/msdn/library/ja/csref/html/vclrfindexedpropertiespg.asp

$B$+$i0zMQ$7$^$9!#(B

|| $BB>$***@8l$,4{Dj$N%$%s%G%C%/%9IU$-%W%m%Q%F%#$KBP$7$F;HMQ$G$-(B
|| $B$kL>A0$r%$%s%G%/%5$***@_Dj$9$k$K$O!"@k8@$NCf$GL>A0B0@-$r;HMQ(B
|| $B$7$^$9!#$?$H$($P!"<!$N$h$&$J>l9g$G$9!#(B

|| [System.Runtime.CompilerServices.CSharp.IndexerName("MyItem")]
|| public int this [int index] // Indexer declaration
|| {
|| }
||
|| $B$3$N%$%s%G%/%5$NL>A0$O(B MyItem $B$K$J$j$^$9!#L>A0B0@-$r;XDj$7(B
|| $B$J$$$H!"4{Dj$NL>A0(B Item $B$K$J$j$^$9!#(B

$B$H$$$&$3$H$G!"L>A0B0@-$r;XDj$7$F$$$J$$$N$G!"(BItem $B$H$$$&L>A0(B
$B$,<+F0E*$K$D$$$F$$$k$h$&$G$9$M!#(B

$B$A$J$_$K!"$*$j$3$&$5$s$K$J$C$?$HI>H=$N!"(BVisual Studio 2005
$B$N(B IDE $B$G$O!"!VI=<($G$-$^$;$s!W$J$I$H$O$J$i$J$$Be$o$j$K!"(B
$B!V(BItem$B!W<+BN$bI=<($5$l$^$;$s$G$7$?!#(B

---
MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
kaok.Web = "http://www.antoine.st/";
AnswerSoft(M.Fudano)
2005-01-13 13:59:37 UTC
Permalink
$B!V$+$*$/!W$5$s!"$I$&$bM-Fq$&8f:B$$$^$9!#(B!(^^)!$B$U!A$G$9!#(B
Post by Kaoru Kodaka
|| [System.Runtime.CompilerServices.CSharp.IndexerName("MyItem")]
|| public int this [int index] // Indexer declaration
|| {
|| }
$B;d$O!"$3$NJU!"8+F($7$?$h$&$G$9!#IaDL$O5$$K$7$J$$=j$G$9$,%V%D%V%D(B....
$B%X%k%W$ONI$/M}2r$9$kI,MW$,M-$j$^$7$?!#$^$?!"$*@$OC$K$J$j$^$7$?!#(B

$B!V(BSystem.Runtime.CompilerServices.CSharp.IndexerName("MyItem")$B!W(B
$B$G!"$3$N$*<v$$$O2?$N;v$+%5%C%Q%jJ,$+$i$J$+$C$?$N$G$9$,!"%X%k%W$K$+$i(B

$B!X(BSystem.Runtime.CompilerServices $BL>A06u4V$O!"%^%M!<%8(B $B%3!<%I$r;HMQ$7$F!"(B
$B6&***@8l%i%s%?%$%`$N<B9T;~$NF0:n$K1F6A$rM?$($k%a%?%G!<%?$NB0@-$r;XDj$9$k(B
$B5!G=$r%3%s%Q%$%i(B $B%i%$%?$KM?$($^$9!#!Y(B

$B$H8@$&$3$H$G!"%3%s%Q%$%i$X$NL?Na$N$h$&$G$9!#(B(^_^;)

$B!V(BCSharp.IndexerName("MyItem")$B!W$3$N8eH>$N0UL#$O$H8@$$$^$9$H(B
$B!V(BCSharp$B!W$H8@$$$^$9$N$O!V(BC#$***@8l!W!"<B:]$K$OITMW$N$h$&$G$9!)!)!)(B
$B;D$j$N!V(BIndexerName("MyItem")$B!W$3$NJU$,%X%k%W$h$j(B

$B!X%$%s%G%/%5$rD>@\%5%]!<%H$7$F$$$J$$%W%m%0%i%_%s%***@8l$G%$%s%G%/%5$r(B
$B3NG'$G$-$kL>A0$r<($7$^$9!#$3$N7?$N$9$Y$F$N%a%s%P$N0lMw$K$D$$$F$O!"(B
IndexerNameAttribute $B%a%s%P(B $B$r;2>H$7$F$/$@$5$$!#!Y(B

$B$H$N;v$G$9!#(BIndexerName$B!]!d(BIndexerNameAttribute$B$***@bL@$GNI$$$h$&$G$9!#(B

Visual Studio 2003$B$G$O!"2<5-%3!<%I$G>e<j$/%3%s%Q%$%k=PMh$F$$$^$9!#(B

[System.Runtime.CompilerServices.IndexerName("NewIndexerName")]
public int this [ int index ]
{
}

http://www.csharpsoft.com/css/article.php?sid=74

$B$3$NJU$G$bF1MM$KL>A0$rIU$1$k$N$,N.57$N$h$&$G$7$?!#(B
Post by Kaoru Kodaka
$B$A$J$_$K!"$*$j$3$&$5$s$K$J$C$?$HI>H=$N!"(BVisual Studio 2005
$B$N(B IDE $B$G$O!"!VI=<($G$-$^$;$s!W$J$I$H$O$J$i$J$$Be$o$j$K!"(B
$B!V(BItem$B!W<+BN$bI=<($5$l$^$;$s$G$7$?!#(B
$B0lEY%@%&%s%m!<%I$7$F!"A4$/F1$8$h$&$G$7$?$N$G%"%s%$%s%9%H!<%k$7$F(B
$B$$$^$7$?!#$=$s$J$KNI$$$N$G$9$+!)!!$^$@!"(BVisual Studio 2005$B$NL5NA(B
$B%Y!<%?!<HG$,%@%&%s%m!<%I$G$-$k$H$*$b$$$^$9$N$G<B83$7$F$_$^$9!#(B
$B!!(B
$B$+$*$/$5$s!"M-Fq$&8f:B$$$^$7$?!#(B

Loading...