Curtis Rutland's Profile User Rating: *****

Reputation: 4419 Guru
Group:
Moderators
Active Posts:
7,813 (5.19 per day)
Joined:
08-June 10
Profile Views:
69,105
Last Active:
User is online A minute ago
Currently:
Viewing Board Index

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Chevrolet
Dream Kudos:
1000
Expert In:
C#, LINQ, Dynamics CRM 2011

Latest Visitors

Icon   Curtis Rutland has been promoted!

Posts I've Made

  1. In Topic: Help me improve my code?

    Posted 21 Jul 2014

    View PostCodingSup3rnatur@l-360, on 19 July 2014 - 06:16 PM, said:

    However, the best solution is to make use of the highest level tools we have available that will do this job, and simply do:

    Spoiler


    Excellently put. A mark of a well experienced programmer is efficiently using the language's/framework's tools to be both expressive and concise.

    Anyone can read your method from top to bottom and know what it does, even a very inexperienced programmer. They may not know what File is or that .Take is an extension method, but they could reasonably guess that it "Reads Lines from a File and Takes so many lines to read".

    And @AToastedBiscuit, don't worry that you may not have known about these constructs, as others have said. This comes from working with the tools, learning what they have to offer, and refining your style over time. It's more efficient to use the tools that others have provided you with than write the tool from scratch, so as you find more and more built-in tools, you get more and more efficient with writing code.

    [quote]I would be interested to see an example using yield though
    @andrewsw, here's how I would re-write the example with a yield keyword:

            static IEnumerable<string> ReadLines(string filePath, int linesToRead)
            {
                if (filePath == null)
                {
                    throw new ArgumentNullException("filePath");
                }
    
                if (linesToRead < 0)
                {
                    throw new ArgumentOutOfRangeException("linesToRead", "Must be zero or greater");
                }
    
                using (StreamReader reader = new StreamReader(filePath))
                {
                    for (int i = 0; i < linesToRead; i++)
                    {
                        string line = reader.ReadLine();
    
                        if (line == null) { yield break; }
                        yield return line;
                    }
                }
            }
    


    Alternatively, I wouldn't bother giving it a linesToRead parameter, because we can use .Take on the call instead.

            static IEnumerable<string> ReadLines(string filePath)
            {
                if (filePath == null)
                {
                    throw new ArgumentNullException("filePath");
                }
    
                using (StreamReader reader = new StreamReader(filePath))
                {
                    while(!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
    
                        if (line == null) { yield break; }
                        yield return line;
                    }
                }
            }
    
    
  2. In Topic: Save a excel

    Posted 17 Jul 2014

    Noorul_A, something important to learn is to not try to do everything on one line. It makes it harder to read, and harder to debug.

    Break it out to another line:
    string path = Output_path + "CRM Opp -" + BU_Name + "-" + output;
    

    Then, try to put it together on paper the same way the computer would. You know what the values of each of these variables is. Output_path = "D:\new folder". Let's pretend that BU_Name = "some business unit" and output = "someoutput".

    If you just add those strings together, you get this:

    "D:\newfolderCRM Opp -some business unit-someoutput"
    


    The code is only mashing together strings. If you want to include another string in there, just add it.

    string path = Output_path + "\\" + "CRM Opp -" + BU_Name + "-" + output;
    


    Note, you have to use "\\" because the backslash character is C#'s "escape character". It allows you to represent unprintable characters with text. To represent a backslash itself, you use two.

    However, Skydiver showed a much better method to use: Path.Combine. It's designed to put parts of folder and file paths together as one.

    Also, I'd like to point out that the pattern may not look like you think it looks. Notice how there's a space before the first dash, but not after the last, etc...

    You should also learn how to use string.Format. It will make composing strings much, much easier.

    string path = string.Format("{0}\\CRM Opp - {1} - {2}", Output_path, BU_Name, output);
    


    Each "{0}" is a placeholder. They're ordered from 0 up. The parameters after the string get "stuck in" where they belong. It's basically a way to make a "template string" and fill in the template.



    To others: please try to keep replies focused on helping the OP. Don't just throw in links you think might happen to have some information possibly related to the question. It clutters the thread and confuses those looking for help. Participation is awesome, just please keep it relevant and actionable.
  3. In Topic: Method issue in code

    Posted 17 Jul 2014

    I'm a fan of _field. It makes sure you don't accidentally use a field instead of a property, and you can get a quick list of your fields in IntelliSense by typing an underscore. And since I only use that for fields, I don't need to identify them as members vs. local, since only members will ever have an underscore, and locals won't.
  4. In Topic: Funny Customer Stories

    Posted 16 Jul 2014

    Well, if we're telling funny name stories, just a few days ago at work someone discovered a local grocery delivery service was doing a promo, they'd deliver a pint of ice cream with no delivery fee. Silly promo, but someone signs up for it. They get the email that their delivery driver today will be "Dickson Berry". We all had a moment of "were his parents never children?" moment. Kids are brutal and I can't imagine he had an easy time of it.
  5. In Topic: Should I buy the older Visual Studio

    Posted 16 Jul 2014

    That's a good point too; I assumed that he needed the features missing from the Express versions.

    But in that case, why not just use the free version until you get a paying gig that you need to have a license for? Why spend the money now when you might go a different direction later?

My Information

Member Title:
(╯□)╯︵ (~ .o.)~
Age:
29 years old
Birthday:
August 29, 1984
Gender:
Location:
San Antonio
Forum Leader:
C#
Full Name:
Curtis Rutland
Years Programming:
7
Programming Languages:
C# -- Forms, WPF, Silverlight, WCF

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://curtisrutland.com
Skype:
Skype  insertAlias_bytes
Twitter:
curtisrutland

Comments

  • (2 Pages)
  • +
  • 1
  • 2
  1. Photo

    NewRandomUsername Icon

    06 Jun 2014 - 20:59
    Did you get my messages(emails) sir?
  2. Photo

    BenignDesign Icon

    03 May 2013 - 13:29
    I see you were staring at my profile. I also stare randomly at profiles. We have much in common. We should probably hook up sometime. Just sayin.
  3. Photo

    eric wallace Icon

    31 Jan 2013 - 02:53
    can you help for visual basic
  4. Photo

    no2pencil Icon

    06 Dec 2012 - 08:34
    It still isn't good enough.
  5. Photo

    ikram002p Icon

    27 Jun 2012 - 10:51
    "It Doesn't Work!" That's not good enough!
    It Still Doesn't Work!.
    I didnt undestand it ??
  6. Photo

    tlhIn`toq Icon

    18 Mar 2012 - 11:22
    Congrats on breaking 3000
  7. Photo

    Curtis Rutland Icon

    08 Sep 2011 - 14:13
    "Leveling up." I like that!
  8. Photo

    MATTtheSEAHAWK Icon

    08 Sep 2011 - 13:55
    Yar ya see, i remember when yee wer purple!
    Anyways congrats! It's weird seeing people who've been one way so long "leveling up" :P.
  9. Photo

    Curtis Rutland Icon

    08 Sep 2011 - 12:59
    Thanks!
  10. Photo

    Sergio Tapia Icon

    08 Sep 2011 - 12:29
    Congrats on becoming a mod. :D
  11. Photo

    Ace26 Icon

    15 Jun 2011 - 13:39
    Hi mate, interesting to see we are age mates. Nice work you do in the forums.
    Just dropped by to say hi, anyways.
    Cheers.
  12. Photo

    RetardedGenius Icon

    20 Apr 2011 - 18:56
    Excellent C# tutorials, they've taught me a lot I didn't know. Please keep more of the good stuff coming! :D
  13. Photo

    Curtis Rutland Icon

    24 Mar 2011 - 14:55
    Yeah, felt like "professionalizing".
  14. Photo

    Dogstopper Icon

    23 Mar 2011 - 17:08
    Woah. Name switch! I took a double take...
  15. Photo

    CodingSup3rnatur@l-360 Icon

    01 Mar 2011 - 14:35
    No problem at all. Glad I could contribute :)
  • (2 Pages)
  • +
  • 1
  • 2