Salut
Existe-t-il une diff�rence entre string et String ?
Et y'a-t-il un avantage � utiliser l'un plut�t que l'autre ?
Merci !
Salut
Existe-t-il une diff�rence entre string et String ?
Et y'a-t-il un avantage � utiliser l'un plut�t que l'autre ?
Merci !
Aucune diff�rence: String repr�sente le type et string est un alias vers ce type.
C'est comme Int32 et int.
A+
Thomas LEBRUN: MCAD.NET, MCTS (Win et Web), MCPD(Win et Web) & Microsoft MVP Client Application Development
WPF par la pratique, mon livre sur WPF ! (�galement disponible ici ou l�)
A la d�couverte de .NET
Non ce n'est pas vraiment �a.
string est un alias (donc exactement la m�me chose) de String.
Int32 est un objet encapsulant le type primitif int.
Ca n'est pas la m�me chose.
Int32 permet d'avoir un objet "de type int" pour tous les cas o� on ne peut pas manipuler un type primitif.
La conversion de int vers Int32 (et inversement) a un co�t.
Ta remarque est interressante duncan55, peux-tu nous offrir quelques liens � ce proposEnvoy� par duncan55
![]()
Non, int est bien un simple alias vers System.Int32 , c'est la m�me chose. (c'est en tout cas ce qui est dit dans les sp�cifications du langage, voir ici , paragraphe 11.1.4).
Autant pour moi, j'avais mal compris, int est bien identique � Int32.
Cela signifie donc qu'un champs int est un objet ?
Il n'est pas possible d'avoir juste une valeur enti�re sans la notion de r�f�rence des objets ?
EDIT:
Cela signifie que Int32 n'est pas un objet ?The example
is more interesting. An int value can be converted to object and back again to int. This example shows
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8 class Test { static void Main() { int i = 123; object o = i; // boxing int j = (int) o; // unboxing } }
both boxing and unboxing. When a variable of a value type needs to be converted to a reference type, an
object box is allocated to hold the value, and the value is copied into the box. Unboxing is just the opposite.
When an object box is cast back to its original value type, the value is copied out of the box and into the
appropriate storage location.
ou alors, C'est le compilateur qui fait le boxing en cas d'utilisation des m�thodes "objets" de Int32.
Partager