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. The Lounge
  3. Picking Up C# or How I typed my fingers to the bone

Picking Up C# or How I typed my fingers to the bone

Scheduled Pinned Locked Moved The Lounge
csharpquestionworkspace
24 Posts 15 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.
  • B Offline
    B Offline
    betterc
    wrote on last edited by
    #1

    I'm an old guy. I've gone up the technical ranks to run a couple of significant software development groups; suffered the crash and now code for a living. I haven't coded in every programing language known, but then, I've got quite a few nothes on my pocket protector. I love C# but I don't think I've typed so much since the days of 'Big 8' COBOL. I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); It works but I think I've only got another C# project before I'll need to replace my keyboard. I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. :-D:-D:-D:-D

    A D R D C 7 Replies Last reply
    0
    • B betterc

      I'm an old guy. I've gone up the technical ranks to run a couple of significant software development groups; suffered the crash and now code for a living. I haven't coded in every programing language known, but then, I've got quite a few nothes on my pocket protector. I love C# but I don't think I've typed so much since the days of 'Big 8' COBOL. I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); It works but I think I've only got another C# project before I'll need to replace my keyboard. I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. :-D:-D:-D:-D

      A Offline
      A Offline
      Anders Molin
      wrote on last edited by
      #2

      well, \r\n still works fine I use it all the time, and you might try to look up using in MSDN :rolleyes: - Anders Money talks, but all mine ever says is "Goodbye!" ShotKeeper, my Photo Album / Organizer Application[^]
      My Photos[^]

      B 1 Reply Last reply
      0
      • A Anders Molin

        well, \r\n still works fine I use it all the time, and you might try to look up using in MSDN :rolleyes: - Anders Money talks, but all mine ever says is "Goodbye!" ShotKeeper, my Photo Album / Organizer Application[^]
        My Photos[^]

        B Offline
        B Offline
        betterc
        wrote on last edited by
        #3

        As I recall ... the time I had to use it was with the AppendText method. Since then, I don't even think about it and just type it out. Use MSDN all the time. :-D:-D:-D:-D:-D Thanks, cb

        1 Reply Last reply
        0
        • B betterc

          I'm an old guy. I've gone up the technical ranks to run a couple of significant software development groups; suffered the crash and now code for a living. I haven't coded in every programing language known, but then, I've got quite a few nothes on my pocket protector. I love C# but I don't think I've typed so much since the days of 'Big 8' COBOL. I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); It works but I think I've only got another C# project before I'll need to replace my keyboard. I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. :-D:-D:-D:-D

          D Offline
          D Offline
          Daniel Turini
          wrote on last edited by
          #4

          Most Z80 instructions were 2~4 letters (JP, LD, CALL, BCD, JNZ, JZ). All the 16-bit registers were two letters (AF, BC, DE, HL, IX, IY), but could be used as two 8-bit registers with only one letter. So, the following line was a valid Z80 instruction:

          LD B,D

          In C#, this would be the following:

          byte B;
          byte D;
          B = D;

          I don't know why, but I do prefer working in C# than in Z80, even though I type more. And, maybe, Intelissense can help you :-D Yes, even I am blogging now!

          B M 2 Replies Last reply
          0
          • D Daniel Turini

            Most Z80 instructions were 2~4 letters (JP, LD, CALL, BCD, JNZ, JZ). All the 16-bit registers were two letters (AF, BC, DE, HL, IX, IY), but could be used as two 8-bit registers with only one letter. So, the following line was a valid Z80 instruction:

            LD B,D

            In C#, this would be the following:

            byte B;
            byte D;
            B = D;

            I don't know why, but I do prefer working in C# than in Z80, even though I type more. And, maybe, Intelissense can help you :-D Yes, even I am blogging now!

            B Offline
            B Offline
            betterc
            wrote on last edited by
            #5

            Don't anybody get me wrong, I am having a love afair with C#. I just finding my self kind of chuckling as I'm typing along. cb

            1 Reply Last reply
            0
            • B betterc

              I'm an old guy. I've gone up the technical ranks to run a couple of significant software development groups; suffered the crash and now code for a living. I haven't coded in every programing language known, but then, I've got quite a few nothes on my pocket protector. I love C# but I don't think I've typed so much since the days of 'Big 8' COBOL. I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); It works but I think I've only got another C# project before I'll need to replace my keyboard. I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. :-D:-D:-D:-D

              R Offline
              R Offline
              Rocky Moore
              wrote on last edited by
              #6

              betterc wrote: when I googled to find that to get my application path I needed to enter Have you tried the property: Application.ExecutablePath Assuming you are working on a WinForm app.. Rocky <>< www.HintsAndTips.com www.MyQuickPoll.com - 2004 Election poll is #33 www.GotTheAnswerToSpam.com

              B 1 Reply Last reply
              0
              • B betterc

                I'm an old guy. I've gone up the technical ranks to run a couple of significant software development groups; suffered the crash and now code for a living. I haven't coded in every programing language known, but then, I've got quite a few nothes on my pocket protector. I love C# but I don't think I've typed so much since the days of 'Big 8' COBOL. I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); It works but I think I've only got another C# project before I'll need to replace my keyboard. I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. :-D:-D:-D:-D

                D Offline
                D Offline
                dnmanner
                wrote on last edited by
                #7

                betterc wrote: But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Environment.CurrentDirectory also gets the application path. It's a bit easier on the keyboard. :) betterc wrote: I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. I once came across (alright, wrote :|) this code to decrypt a file: string Decrypted = System.Text.ASCIIEncoding.ASCII.GetString(new System.Security.Cryptography.TripleDESCryptoServiceProvider().CreateDecryptor(System.Text.Encoding.ASCII.GetBytes(xdoc.SelectSingleNode(System.Configuration.ConfigurationSettings.AppSettings["key"]).InnerText), System.Text.Encoding.ASCII.GetBytes(xdoc.SelectSingleNode(System.Configuration.ConfigurationSettings.AppSettings["iv"]).InnerText)).TransformFinalBlock(System.Convert.FromBase64String(System.IO.File.OpenText(System.Configuration.ConfigurationSettings.AppSettings["filepath"]).ReadToEnd()), 0, System.Configuration.ConfigurationSettings.AppSettings["length"])); Dan

                B R P P 4 Replies Last reply
                0
                • R Rocky Moore

                  betterc wrote: when I googled to find that to get my application path I needed to enter Have you tried the property: Application.ExecutablePath Assuming you are working on a WinForm app.. Rocky <>< www.HintsAndTips.com www.MyQuickPoll.com - 2004 Election poll is #33 www.GotTheAnswerToSpam.com

                  B Offline
                  B Offline
                  betterc
                  wrote on last edited by
                  #8

                  Wow, that's pretty good but it returns the path plust the executable .exe file. So I'll have to strip off the xxx.exe. BTW the above example I used (which I got off of MSDN) retuns the path prepended with "file:\". So there I have to strip the begining off. So one way or the other it will take 2 statments to get the path to the applicaiton. Again, I'm not complaining just stunned once in a while. cb :-D:-D

                  C 1 Reply Last reply
                  0
                  • B betterc

                    I'm an old guy. I've gone up the technical ranks to run a couple of significant software development groups; suffered the crash and now code for a living. I haven't coded in every programing language known, but then, I've got quite a few nothes on my pocket protector. I love C# but I don't think I've typed so much since the days of 'Big 8' COBOL. I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); It works but I think I've only got another C# project before I'll need to replace my keyboard. I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. :-D:-D:-D:-D

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    betterc wrote: I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. Yes, but you can use \n\r, you just won't be guarenteed that it will always work ( i.e. Environment.NewLine will work no matter what the system requires to achieve that result ). betterc wrote: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); I doubt this is the quickest way to do this, but having said that, if C# suffers from anything, it's forced object orientation, which means, for example, that Floor is Math.Floor, because everything needs to live in a class. You could also have made the code more readable by a few using statements at the top of the class. :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                    J 1 Reply Last reply
                    0
                    • D dnmanner

                      betterc wrote: But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Environment.CurrentDirectory also gets the application path. It's a bit easier on the keyboard. :) betterc wrote: I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. I once came across (alright, wrote :|) this code to decrypt a file: string Decrypted = System.Text.ASCIIEncoding.ASCII.GetString(new System.Security.Cryptography.TripleDESCryptoServiceProvider().CreateDecryptor(System.Text.Encoding.ASCII.GetBytes(xdoc.SelectSingleNode(System.Configuration.ConfigurationSettings.AppSettings["key"]).InnerText), System.Text.Encoding.ASCII.GetBytes(xdoc.SelectSingleNode(System.Configuration.ConfigurationSettings.AppSettings["iv"]).InnerText)).TransformFinalBlock(System.Convert.FromBase64String(System.IO.File.OpenText(System.Configuration.ConfigurationSettings.AppSettings["filepath"]).ReadToEnd()), 0, System.Configuration.ConfigurationSettings.AppSettings["length"])); Dan

                      B Offline
                      B Offline
                      betterc
                      wrote on last edited by
                      #10

                      You Win! cb:-D:-D:-D

                      1 Reply Last reply
                      0
                      • B betterc

                        Wow, that's pretty good but it returns the path plust the executable .exe file. So I'll have to strip off the xxx.exe. BTW the above example I used (which I got off of MSDN) retuns the path prepended with "file:\". So there I have to strip the begining off. So one way or the other it will take 2 statments to get the path to the applicaiton. Again, I'm not complaining just stunned once in a while. cb :-D:-D

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #11

                        betterc wrote: So I'll have to strip off the xxx.exe. Easily done in the same line with a Regex. :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                        D 1 Reply Last reply
                        0
                        • C Christian Graus

                          betterc wrote: So I'll have to strip off the xxx.exe. Easily done in the same line with a Regex. :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                          D Offline
                          D Offline
                          David Stone
                          wrote on last edited by
                          #12

                          Or how about System.IO.Path.GetFileNameWithoutExtension? ;) [EDIT]Derrr. That's what I get for trying to be a smart ass. It's actually System.IO.Path.GetDirectoryName() [/EDIT]


                          Lest some forgot their humour pill this morning: I am writing this with Moz (actually FireFox but still Moz) and love the damned browser. It's a joke, see. -Paul Watson on FireFox

                          P 1 Reply Last reply
                          0
                          • D Daniel Turini

                            Most Z80 instructions were 2~4 letters (JP, LD, CALL, BCD, JNZ, JZ). All the 16-bit registers were two letters (AF, BC, DE, HL, IX, IY), but could be used as two 8-bit registers with only one letter. So, the following line was a valid Z80 instruction:

                            LD B,D

                            In C#, this would be the following:

                            byte B;
                            byte D;
                            B = D;

                            I don't know why, but I do prefer working in C# than in Z80, even though I type more. And, maybe, Intelissense can help you :-D Yes, even I am blogging now!

                            M Offline
                            M Offline
                            Marc Clifton
                            wrote on last edited by
                            #13

                            Daniel Turini wrote: In C#, this would be the following: I disagree. Since "B" and "D" are registers that were already defined, declaring them with: byte B; byte D; is technically not correct, IMO, since in Z80, they are already "declared". So, "LD B,D" in C# would actually be "B=D;" which is 3 characters LESS! :-D Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog Hunt The Wumpus RealDevs.Net

                            1 Reply Last reply
                            0
                            • C Christian Graus

                              betterc wrote: I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. Yes, but you can use \n\r, you just won't be guarenteed that it will always work ( i.e. Environment.NewLine will work no matter what the system requires to achieve that result ). betterc wrote: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); I doubt this is the quickest way to do this, but having said that, if C# suffers from anything, it's forced object orientation, which means, for example, that Floor is Math.Floor, because everything needs to live in a class. You could also have made the code more readable by a few using statements at the top of the class. :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                              J Offline
                              J Offline
                              Jon Pawley
                              wrote on last edited by
                              #14

                              My Floor lives in My House, not in a class. Jon ;P

                              R 1 Reply Last reply
                              0
                              • J Jon Pawley

                                My Floor lives in My House, not in a class. Jon ;P

                                R Offline
                                R Offline
                                Ryan Binns
                                wrote on last edited by
                                #15

                                So you use House.Floor() instead of Math.Floor() ? ;P :rolleyes:

                                Ryan

                                "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                                J 1 Reply Last reply
                                0
                                • D dnmanner

                                  betterc wrote: But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Environment.CurrentDirectory also gets the application path. It's a bit easier on the keyboard. :) betterc wrote: I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. I once came across (alright, wrote :|) this code to decrypt a file: string Decrypted = System.Text.ASCIIEncoding.ASCII.GetString(new System.Security.Cryptography.TripleDESCryptoServiceProvider().CreateDecryptor(System.Text.Encoding.ASCII.GetBytes(xdoc.SelectSingleNode(System.Configuration.ConfigurationSettings.AppSettings["key"]).InnerText), System.Text.Encoding.ASCII.GetBytes(xdoc.SelectSingleNode(System.Configuration.ConfigurationSettings.AppSettings["iv"]).InnerText)).TransformFinalBlock(System.Convert.FromBase64String(System.IO.File.OpenText(System.Configuration.ConfigurationSettings.AppSettings["filepath"]).ReadToEnd()), 0, System.Configuration.ConfigurationSettings.AppSettings["length"])); Dan

                                  R Offline
                                  R Offline
                                  Ryan Binns
                                  wrote on last edited by
                                  #16

                                  dnmanner wrote: I once came across (alright, wrote :|) this code to decrypt a file: :wtf:!!

                                  Ryan

                                  "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                                  1 Reply Last reply
                                  0
                                  • B betterc

                                    I'm an old guy. I've gone up the technical ranks to run a couple of significant software development groups; suffered the crash and now code for a living. I haven't coded in every programing language known, but then, I've got quite a few nothes on my pocket protector. I love C# but I don't think I've typed so much since the days of 'Big 8' COBOL. I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. But I really had to grin when I googled to find that to get my application path I needed to enter: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); It works but I think I've only got another C# project before I'll need to replace my keyboard. I think we need a contest on what is the longest statement possible in c# to retrieve a smiple result. There are 8 dots between the = sign and the ; in the above snippet. :-D:-D:-D:-D

                                    J Offline
                                    J Offline
                                    jan larsen
                                    wrote on last edited by
                                    #17

                                    betterc wrote: I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. As other people have stated, you can always use '\r\n'. But .NET is supposed to be platform independant, so if someone was trying to run your application on MONO on a linux, then they would probably be very disappointed if the output files from your program were splattered with '\r\n' instead of just '\n'. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

                                    R 1 Reply Last reply
                                    0
                                    • D David Stone

                                      Or how about System.IO.Path.GetFileNameWithoutExtension? ;) [EDIT]Derrr. That's what I get for trying to be a smart ass. It's actually System.IO.Path.GetDirectoryName() [/EDIT]


                                      Lest some forgot their humour pill this morning: I am writing this with Moz (actually FireFox but still Moz) and love the damned browser. It's a joke, see. -Paul Watson on FireFox

                                      P Offline
                                      P Offline
                                      peterchen
                                      wrote on last edited by
                                      #18

                                      Yep, the correct function would be System.IO.Path.GetFileNameWithoutExtensionButFinalBackslashInPlaceJustInCaseYouNeeditThere


                                      we are here to help each other get through this thing, whatever it is Vonnegut jr.
                                      sighist || Agile Programming | doxygen

                                      1 Reply Last reply
                                      0
                                      • J jan larsen

                                        betterc wrote: I get a chuckle on how much I have to type to get something so small done. I thought I'd seen everything when I found that a \n\r was replaced by an 'Environment.Linefeed'. As other people have stated, you can always use '\r\n'. But .NET is supposed to be platform independant, so if someone was trying to run your application on MONO on a linux, then they would probably be very disappointed if the output files from your program were splattered with '\r\n' instead of just '\n'. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

                                        R Offline
                                        R Offline
                                        Rocky Moore
                                        wrote on last edited by
                                        #19

                                        jan larsen wrote: But .NET is supposed to be platform independant Hmmm.. Really? I know people are trying to make it that way but it is built to be Platform "dependant"... Rocky <>< www.HintsAndTips.com www.MyQuickPoll.com - 2004 Election poll is #33 www.GotTheAnswerToSpam.com

                                        J 1 Reply Last reply
                                        0
                                        • R Rocky Moore

                                          jan larsen wrote: But .NET is supposed to be platform independant Hmmm.. Really? I know people are trying to make it that way but it is built to be Platform "dependant"... Rocky <>< www.HintsAndTips.com www.MyQuickPoll.com - 2004 Election poll is #33 www.GotTheAnswerToSpam.com

                                          J Offline
                                          J Offline
                                          jan larsen
                                          wrote on last edited by
                                          #20

                                          Rocky Moore wrote: but it is built to be Platform "dependant"... Not really, it's like with Java, you just need the runtime engine for your target platform. At the time you only get the full compliance on (some) Win32, but there is a limited runtime for Linux. I agree though that there are som errors in the design, eg. The Form class which exposes the native win32/win64 handle. But that is where the skill as a programmer comes in :-), it should be possible to work around such issues. Java actually got a few such issues too, but they are a bit harder to find and exists solely on rarely used operations, such as killing threads explicitly, which wasn't fully supported on Java 1.1 for HP-UX. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

                                          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