[.net][C#] faire un define avec une valeur comme en C ?

faire un define avec une valeur comme en C ? [.net][C#] - C#/.NET managed - Programmation

Marsh Posté le 22-06-2005 à 12:50:37    

Hello,
 
En C on pouvait faire #define toto 10
 
apparemment en C# ce n'est plus possible.
Y a t'il un équivalent ?


---------------
"PAR LE POUVOIR DU CRÂNE ANCESTRAL, JE DETIENS LA FORCE TOUTE PUISSANTE".
Reply

Marsh Posté le 22-06-2005 à 12:50:37   

Reply

Marsh Posté le 22-06-2005 à 12:53:09    

Clarkent a écrit :


 
En C on pouvait faire #define toto 10
 
apparemment en C# ce n'est plus possible.


 
tant mieux :o
 

Clarkent a écrit :


Y a t'il un équivalent ?


 
Un exemple vaut mieux qu'un long discours :o
 

Code :
  1. public class MyXmlNodes
  2.  {
  3.   public const string AccessNone    = "AccessNone";
  4.   public const string AssociationEnd   = "association-end";
  5.   public const string Attribute    = "attribute";
  6.   public const string BaseType    = "base-type";
  7.   public const string Changeable    = "changeable";
  8.   public const string Class     = "class";
  9.   public const string ClassType    = "class-type"


---------------
JE JE SUIS LIBERTINEEEEEEEEEEE JE SUIS UNE CATINNNNNNNNN §§§§§§§§
Reply

Marsh Posté le 22-06-2005 à 12:57:24    

:hello:  
oui c'est possible tu fe un:
 
#define toto 1


Message édité par shikra le 22-06-2005 à 12:58:16
Reply

Marsh Posté le 22-06-2005 à 13:02:09    

oula attend je vien de comprendre tu veut que toto est la valeur 10 c'est ca??ha nan c'est pas possible autant pour moi
Mal g dois me racheter des lunette desole Elianor


Message édité par shikra le 22-06-2005 à 13:03:30
Reply

Marsh Posté le 22-06-2005 à 13:02:12    

shikra a écrit :

:hello:  
oui c'est possible tu fe un:
 
#define toto 1


 
[:petrus75]
 
 
edit : il parle de C# :o
edit : le preprocesseur, c'est taboo, on en viendra tous à bout :o


Message édité par elianor le 22-06-2005 à 13:02:54

---------------
JE JE SUIS LIBERTINEEEEEEEEEEE JE SUIS UNE CATINNNNNNNNN §§§§§§§§
Reply

Marsh Posté le 22-06-2005 à 13:09:22    

elianor, merci mais je connais ca :D, ce qui me plait pas c'est de creer des objets pour ca :D.


---------------
"PAR LE POUVOIR DU CRÂNE ANCESTRAL, JE DETIENS LA FORCE TOUTE PUISSANTE".
Reply

Marsh Posté le 22-06-2005 à 13:12:37    

C'est pas des objets, mais des constantes :??:

Reply

Marsh Posté le 22-06-2005 à 13:17:18    

ha c'estparce que t'as mis le s minuscule j'avais pas vu :D.
et une constante ca peut etre un objet, a moins qu'un truc m echappe.


---------------
"PAR LE POUVOIR DU CRÂNE ANCESTRAL, JE DETIENS LA FORCE TOUTE PUISSANTE".
Reply

Marsh Posté le 22-06-2005 à 13:22:03    

et alors ou est le problème, tu fais de l'orienté objet en C#, pas du séquentiel comme en c, faut inover :D
 

Reply

Marsh Posté le 22-06-2005 à 13:58:48    

static bordel :o
et readonly, const n'as pas vraiment de sens pour les pas-int. sinon ça inline la chaine partout, ce qui est pas terrible


Message édité par Taz le 22-06-2005 à 14:01:20
Reply

Marsh Posté le 22-06-2005 à 13:58:48   

Reply

Marsh Posté le 22-06-2005 à 14:24:35    

static ? la n'est pas le pb.
readonly oui.
 
 
Et fair de l'objet ne signifie pas qu'il faut en mettre partout la ou c'est pas utile :D.


---------------
"PAR LE POUVOIR DU CRÂNE ANCESTRAL, JE DETIENS LA FORCE TOUTE PUISSANTE".
Reply

Marsh Posté le 22-06-2005 à 14:30:55    

enfon bon const et static readonly pas de souci, si y a que ces solutions tant pis ca sera comme ca alors :D.
Merci ;).


---------------
"PAR LE POUVOIR DU CRÂNE ANCESTRAL, JE DETIENS LA FORCE TOUTE PUISSANTE".
Reply

Marsh Posté le 22-06-2005 à 14:34:27    

Le #define du C est quand même beaucoup plus puissant que la simple définition d'une constante.
 
grâce à ça, on peut faire des choses formidables ! des trucs du style :
 

Code :
  1. #define like {
  2. #define man ;}
  3. #define an ;
  4. #define SayBro /*  
  5. #define CheckItOut */
  6. SayBro like, this is some rad program, so CheckItOut
  7. like
  8.      a = b
  9.           an
  10.      c = d
  11. man
  12. SayBro , like who needs help from them compiler choads anyway?
  13. THIS is the way to write CLEAR code.  I mean really!  CheckItOut
  14. like SayBro this is ShellSort straight out of the white book, but in
  15. a readable form.
  16. CheckItOut man
  17. #define YoDude for(
  18. #define OK     )
  19. #define is     =
  20. #define AND    &&
  21. #define as
  22. #define Do
  23. #define long
  24. #define some
  25. #define make
  26. #define garbage
  27. #define FAROUT
  28. shell(v, n) SayBro sort v[0]...v[n-1] into increasing order CheckItOut
  29. int v[], n;
  30. like int gap, i, j, temp;
  31. YoDude gap is n/2 an as long as gap > 0 Do some garbage an make gap /=2 OK
  32.      YoDude i is gap an as long as i < n Do some garbage an make i++ OK
  33.          YoDude j is i - gap an as long as j >= 0 AND v[j] > v[j+gap] Do some
  34.              garbage an make j -= gap OK
  35.              like
  36.                  temp is v[j]      an
  37.                  v[j] is v[j+gap]  an
  38.                  v[j+gap] is temp
  39.              man
  40. FAROUT man


 
( copier sur http://www.developpez.com à la section humour )
Je trouve ce truc délirant :lol:

Reply

Marsh Posté le 22-06-2005 à 14:38:38    

Ouais mais nan :o

Reply

Marsh Posté le 22-06-2005 à 14:53:33    

const est implicitement static, const veut dire 'littérale'.

Reply

Marsh Posté le 22-06-2005 à 15:04:21    


  // "Hello World" in l33t by Stephen McGreal.
   // Note that the views expressed in this source code do not necessarily
   // coincide with those of the author :o)
 
   Gr34t l33tN3$$?  
   M3h...
   iT 41n't s0 7rIckY.
 
   l33t sP33k is U8er keWl 4nD eA5y wehn u 7hink 1t tHr0uGh.
   1f u w4nn4be UB3R-l33t u d3f1n1t3lY w4nt in 0n a b4d4sS h4xX0r1ng s1tE!!! ;p
   w4r3Z c0ll3cT10n2 r 7eh l3Et3r!
 
   Qu4k3 cL4nS r 7eh bE5t tH1ng 1n teh 3nTIr3 w0rlD!!!
   g4m3s wh3r3 u g3t to 5h00t ppl r 70tAl1_y w1cK1d!!
   I'M teh fr4GM4stEr aN I'lL t0t41_1Ly wIpE teh phr34k1ng fL00r ***j3d1 5tYlE***
   wItH y0uR h1dE!!!! L0L0L0L!
   t3lEphR4gG1nG l4m3rs wit mY m8tes r34lLy k1kK$ A$$
 
   l33t hAxX0r$ CrE4t3 u8er- k3wL 5tUff lIkE n34t pR0gR4mm1nG lAnguidGe$...
   s0m3tIm3$ teh l4nGu4gES l00k jUst l1k3 rE41_ 0neS 7o mAkE ppl Th1nk th3y'r3
   ju$t n0rMal lEE7 5pEEk but th3y're 5ecRetLy c0dE!!!!
   n080DY unDer5tAnD$ l33t SpEaK 4p4rT fr0m j3d1!!!!!
   50mE kId 0n A me$$4gEb04rD m1ghT 8E a r0xX0r1nG hAxX0r wH0 w4nT2 t0 bR34k
   5tuFf, 0r mAyb3 ju5t sh0w 7eh wAy5 l33t ppl cAn 8E m0re lIkE y0d4!!!
   hE i5 teh u8ER!!!!
   1t m1ght 8E 5omE v1rus 0r a Pl4ySt4tI0n ch34t c0dE.
   1t 3v3n MiTe jUs7 s4y "H3LL0 W0RLD!!!" u ju5t cAn'T gu3s5.
   tH3r3's n3v3r anY p0iNt l00KiNg sC3pT1c4l c0s th4t, be1_1Ev3 iT 0r n0t, 1s
   whAt th1s 1s!!!!!
 
   5uxX0r5!!!L0L0L0L0L!!!!!!!


http://electrod.ifreepages.com/l33t.htm
 
Et plus globalement http://en.wikipedia.org/wiki/Hello [...] _languages


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 22-06-2005 à 17:07:19    

Ca me rappelle ce site d'anthologie : http://www.tsgk.net/cowboyz/

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed