Picking Up C# or How I typed my fingers to the bone
-
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
My Floor lives in My House, not in a class. Jon ;P
-
My Floor lives in My House, not in a class. Jon ;P
So you use
House.Floor()
instead ofMath.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"
-
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"]));
Dandnmanner 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"
-
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
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
-
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
-
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
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
-
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
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
-
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 -
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
Pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee;P ************************** S r e e j i t h N a i r **************************
-
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"]));
Dandnmanner wrote: Environment.CurrentDirectory also gets the application path. You really must learn the difference between the current directory and the application path. An application can set the current directory, it cannot set it's own path.
[
](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
So you use
House.Floor()
instead ofMath.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"
;P