Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. assign number to variable name

assign number to variable name

Scheduled Pinned Locked Moved C#
tutorial
21 Posts 12 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P pmarfleet

    What happens when you try it?

    Paul Marfleet

    C Offline
    C Offline
    conemajstor
    wrote on last edited by
    #3

    c# dont want to compile it

    nemanja

    P 1 Reply Last reply
    0
    • C conemajstor

      c# dont want to compile it

      nemanja

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #4

      There's your answer then!

      Paul Marfleet

      C 1 Reply Last reply
      0
      • P pmarfleet

        There's your answer then!

        Paul Marfleet

        C Offline
        C Offline
        conemajstor
        wrote on last edited by
        #5

        are you kididng it must be some way to compile it like working with bits and bytes ore such ... or some lists,arrays, ....

        nemanja

        P 1 Reply Last reply
        0
        • C conemajstor

          Is it possible to assign number to variable name to fisrst place example : string 5cake="Good"; int 1name= 1; I bet with the teacher that this is possible so please dont dissapoint me ...:D:D:D Regards Nemanja

          nemanja

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #6

          conemajstor wrote:

          I bet with the teacher that this is possible

          You lose. Not even with the @ identifier specifier does it work: int @int = 1; // Works just fine. int @1name = 1; // Nope. An identifier in C# can never ever start with a digit.

          --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

          D 1 Reply Last reply
          0
          • C conemajstor

            Is it possible to assign number to variable name to fisrst place example : string 5cake="Good"; int 1name= 1; I bet with the teacher that this is possible so please dont dissapoint me ...:D:D:D Regards Nemanja

            nemanja

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #7

            I hope you didn't bet too much, or you could end up buying your teacher a Porsche. He's right, and you're wrong. Variables can't start with a number as you found out when you tried to compile it.

            Deja View - the feeling that you've seen this post before.

            C 1 Reply Last reply
            0
            • P Pete OHanlon

              I hope you didn't bet too much, or you could end up buying your teacher a Porsche. He's right, and you're wrong. Variables can't start with a number as you found out when you tried to compile it.

              Deja View - the feeling that you've seen this post before.

              C Offline
              C Offline
              conemajstor
              wrote on last edited by
              #8

              but if i enum ?? enum(1a,2a,3a,4a,5a)

              nemanja

              D 1 Reply Last reply
              0
              • C conemajstor

                Is it possible to assign number to variable name to fisrst place example : string 5cake="Good"; int 1name= 1; I bet with the teacher that this is possible so please dont dissapoint me ...:D:D:D Regards Nemanja

                nemanja

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #9

                conemajstor wrote:

                I bet with the teacher

                Do you have a gambling problem? That's like betting on a three legged dog!

                C C 2 Replies Last reply
                0
                • C conemajstor

                  are you kididng it must be some way to compile it like working with bits and bytes ore such ... or some lists,arrays, ....

                  nemanja

                  P Offline
                  P Offline
                  pmarfleet
                  wrote on last edited by
                  #10

                  conemajstor wrote:

                  are you kididng

                  Why would I be kididng [sic]? You asked whether variables names that begin with a number are valid. I suggested that you tried it and observed what happened. You tried it and found that it didn't work. By following an empirical approach, you have answered your own question.

                  conemajstor wrote:

                  it must be some way to compile it like working with bits and bytes ore such ... or some lists,arrays, ....

                  This sentence is nonsense. I have no idea what you are talking about.

                  Paul Marfleet

                  R 1 Reply Last reply
                  0
                  • L led mike

                    conemajstor wrote:

                    I bet with the teacher

                    Do you have a gambling problem? That's like betting on a three legged dog!

                    C Offline
                    C Offline
                    conemajstor
                    wrote on last edited by
                    #11

                    my teacher is one peace of shit ... im 92' and i am programming 5 years now and he teaches me whats a computer .. how to switch it off , on, het yells to me when i am not listening him .... and this question is for Pascal but i havent found pascal forum ... we learn pasacl becaues my teacher is 65 years old and dont know anything other .... i won 3 bets allready from him!!!!

                    nemanja

                    P G M T 4 Replies Last reply
                    0
                    • C conemajstor

                      but if i enum ?? enum(1a,2a,3a,4a,5a)

                      nemanja

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #12

                      Enum members are not variables, and even those identifier cannot start with a number. Had you tried it yourself, you would have found out quite easily. But, in either case, you still lose...

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007

                      1 Reply Last reply
                      0
                      • C conemajstor

                        my teacher is one peace of shit ... im 92' and i am programming 5 years now and he teaches me whats a computer .. how to switch it off , on, het yells to me when i am not listening him .... and this question is for Pascal but i havent found pascal forum ... we learn pasacl becaues my teacher is 65 years old and dont know anything other .... i won 3 bets allready from him!!!!

                        nemanja

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #13

                        My sympathys are with your teacher. You don't listen to him, and you still haven't learned your lesson.

                        conemajstor wrote:

                        won 3 bets allready from him

                        But not this one.

                        Deja View - the feeling that you've seen this post before.

                        1 Reply Last reply
                        0
                        • C conemajstor

                          my teacher is one peace of shit ... im 92' and i am programming 5 years now and he teaches me whats a computer .. how to switch it off , on, het yells to me when i am not listening him .... and this question is for Pascal but i havent found pascal forum ... we learn pasacl becaues my teacher is 65 years old and dont know anything other .... i won 3 bets allready from him!!!!

                          nemanja

                          G Offline
                          G Offline
                          Guffa
                          wrote on last edited by
                          #14

                          conemajstor wrote:

                          im 92'

                          You are ninety-two feet? Or did you perhaps mean '92? ;)

                          conemajstor wrote:

                          i am programming 5 years now

                          Oh, a newbie. ;)

                          conemajstor wrote:

                          het yells to me when i am not listening him

                          Go figure...

                          conemajstor wrote:

                          we learn pasacl

                          That's good. Pascal is an excellent language for learning programming.

                          conemajstor wrote:

                          becaues my teacher is 65 years old and dont know anything other

                          I seriously doubt that.

                          conemajstor wrote:

                          i won 3 bets allready from him

                          So now you think that you know anything? ;)

                          --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

                          P 1 Reply Last reply
                          0
                          • G Guffa

                            conemajstor wrote:

                            im 92'

                            You are ninety-two feet? Or did you perhaps mean '92? ;)

                            conemajstor wrote:

                            i am programming 5 years now

                            Oh, a newbie. ;)

                            conemajstor wrote:

                            het yells to me when i am not listening him

                            Go figure...

                            conemajstor wrote:

                            we learn pasacl

                            That's good. Pascal is an excellent language for learning programming.

                            conemajstor wrote:

                            becaues my teacher is 65 years old and dont know anything other

                            I seriously doubt that.

                            conemajstor wrote:

                            i won 3 bets allready from him

                            So now you think that you know anything? ;)

                            --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

                            P Offline
                            P Offline
                            pmarfleet
                            wrote on last edited by
                            #15

                            There's nothing wrong with being 65. Unless you're the leader of the British Liberal Democrats...

                            Paul Marfleet

                            1 Reply Last reply
                            0
                            • L led mike

                              conemajstor wrote:

                              I bet with the teacher

                              Do you have a gambling problem? That's like betting on a three legged dog!

                              C Offline
                              C Offline
                              codemunkeh
                              wrote on last edited by
                              #16

                              10 bucks says it falls down!


                              Ninja (the Nerd)
                              Confused? You will be...

                              1 Reply Last reply
                              0
                              • C conemajstor

                                Is it possible to assign number to variable name to fisrst place example : string 5cake="Good"; int 1name= 1; I bet with the teacher that this is possible so please dont dissapoint me ...:D:D:D Regards Nemanja

                                nemanja

                                A Offline
                                A Offline
                                Anthony Mushrow
                                wrote on last edited by
                                #17

                                You could always... cheat. Fonts, all they are a little pictures really. What is it, courier new that compilers mostly use? Anyway, see if you can get yourself that font, edit out some symbol that is allowed, and make it a number. To the user, the first letter in the variable name is a number, but to the compiler its just a symbol, or another letter. Oh, by the way, cheating is bad. Don't do it ;)

                                My current favourite word is: Waffle Cheese is still good though.

                                1 Reply Last reply
                                0
                                • P pmarfleet

                                  conemajstor wrote:

                                  are you kididng

                                  Why would I be kididng [sic]? You asked whether variables names that begin with a number are valid. I suggested that you tried it and observed what happened. You tried it and found that it didn't work. By following an empirical approach, you have answered your own question.

                                  conemajstor wrote:

                                  it must be some way to compile it like working with bits and bytes ore such ... or some lists,arrays, ....

                                  This sentence is nonsense. I have no idea what you are talking about.

                                  Paul Marfleet

                                  R Offline
                                  R Offline
                                  Ravi Bhavnani
                                  wrote on last edited by
                                  #18

                                  pmarfleet wrote:

                                  This sentence is nonsense.

                                  Your terse and highly accurate observation leaves me no choice but to vote your post a 5. :-D /ravi

                                  This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

                                  1 Reply Last reply
                                  0
                                  • G Guffa

                                    conemajstor wrote:

                                    I bet with the teacher that this is possible

                                    You lose. Not even with the @ identifier specifier does it work: int @int = 1; // Works just fine. int @1name = 1; // Nope. An identifier in C# can never ever start with a digit.

                                    --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

                                    D Offline
                                    D Offline
                                    DavidNohejl
                                    wrote on last edited by
                                    #19

                                    Guffa wrote:

                                    An identifier in C# can never ever start with a digit.

                                    Bonus question: can identifier start with digit in IL? (I gave up after maybe 2 min. of googling :O)


                                    [My Blog]
                                    "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
                                    "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                                    1 Reply Last reply
                                    0
                                    • C conemajstor

                                      my teacher is one peace of shit ... im 92' and i am programming 5 years now and he teaches me whats a computer .. how to switch it off , on, het yells to me when i am not listening him .... and this question is for Pascal but i havent found pascal forum ... we learn pasacl becaues my teacher is 65 years old and dont know anything other .... i won 3 bets allready from him!!!!

                                      nemanja

                                      M Offline
                                      M Offline
                                      MasterSharp
                                      wrote on last edited by
                                      #20

                                      You really need to listen. If he's your teacher, he's better than you. Usually, but now, duh. Period.

                                      The most knowledge doesn't mean the most wise...

                                      1 Reply Last reply
                                      0
                                      • C conemajstor

                                        my teacher is one peace of shit ... im 92' and i am programming 5 years now and he teaches me whats a computer .. how to switch it off , on, het yells to me when i am not listening him .... and this question is for Pascal but i havent found pascal forum ... we learn pasacl becaues my teacher is 65 years old and dont know anything other .... i won 3 bets allready from him!!!!

                                        nemanja

                                        T Offline
                                        T Offline
                                        ThomasBates
                                        wrote on last edited by
                                        #21

                                        > .... and this question is for Pascal but i havent found pascal forum ... Sorry, but it's not valid in Pascal, either. (unless you use the font-edit method below) Thomas Bates I want to live in Theory. Everything works in Theory.

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups