dim. 06 avril 2008, 12h11
Gregory
atoutfox.public.association
Re: C#, c'est merveilleux - Olivier
Olivier,
Les indices commencent a zero - c'etait deja comme ca en C
J'aime bien, cela a ses avantages
string[] aa = { "1", "2", "3" };
aa.GetLowerBound(0) >> 0
aa.GetUpperBound(0) >> 2
Mais, c'est logique
for( int i = aa.GetLowerBound(0), i<= aa.GetUpperBound(0), i++)
..... ;
Si tu n'as qu'une dimension, qui demarre a zero, tu prends aa.Length() -1
S'il y a des methodes GetLowerBound(), GetUpperBound(), il y a bien une
raison
Il y a moyen de declarer des tableaux avec des GetLowerBound() <> 0
static void doit()
{
int[] longueur = { 2, 3 };
int[] lowerbound = { -3, 2 };
int[] accessor = new int[2];
;
Array tab = Array.CreateInstance(typeof(string), longueur,
lowerbound);
for (int i = tab.GetLowerBound(0); i <= tab.GetUpperBound(0);
i++)
{
accessor[0] = i;
for (int j = tab.GetLowerBound(1); j <=
tab.GetUpperBound(1); j++)
{
accessor[1] = j;
tab.SetValue(i.ToString() + " , " + j.ToString(),
accessor);
Console.WriteLine(tab.GetValue(accessor));
}
}
}
/*
-3, 2
-3, 3
-3, 4
-2, 2
-2, 3
-2, 4
*/
Gregory
_
"OlivierH" <"nospam[contact]"@planitron.com> wrote in message
news:fta0rm$139t$1@news.niouzes.net...
> Autre inconvenient, pour debugger quand on est
> en train de convertir de vfp à C# , les indices commencent à zero
>
> Pour retourner le nombre de ligne d'un tableau,
> si j'ai 10 lignes
> TAB.GetUpperBound(0) = il me renvoit 9 !
>
> Pas tres normal, je trouve !
>
> Olivier
>
>
>
>
> OlivierH a écrit :
>> L'aide en ligne est horrible,
>>
>> Olivier
>>
>>
>>
>> Gregory a écrit :
>>> On perd des fois une heure a chercher un truc,
>>> une demi heure a comprendre une erreur de compilation,
>>> mais a part ca - c'est tres bien
>>>
--
Gregory
__
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000002184