Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Discussions

amotif amotif No Silver Bullet
  • C# array constructor & ​initializat​ion

    janzenr wrote:
    I am under the impression that:

    new String[] { "foo", "bar"};

    and

    new String();

    are just constructors.   new String(); does not new up to anything, unlike the behavior of the array, right? 


        new String[] { "foo", "bar"};

    allocates and array and assigns elements

        new String();

    would allocate a String instance, if it actually compiled. It won't compile because there is no default ctor for String (String is immutable, so it wouldn't make much sense).

        new Object();

    This compiles and creates a new instance of Object. Your "does not new up to anything" statement isn't correct, as far as I understand your words.

    janzenr wrote:
    Also if I pass new String[] { "Foo", "bar"} as a function's parameter, it compiles. Ex:

    Console.WriteLine(new String[] { "foo", "bar" });

    We still have a problem here.


    I don't see the problem. Your example of passing the initialized array as a parameter is a completely different context than your original question, which tries to use the initialized array as a statement unto itself. And *that* is the subject of the error message you get.

    As to "why," I'd guess that has something to do with the language spec.

  • What's the functional programming / Linq form of this?

    amotif wrote:
    Anyone know how to format this to "5=>a,e" etc. in a linq-esque fashion?


    Okay, I think I've settled on this:

        var result = from pair in data
                     group pair by pair.Value into g
                     select g.FormatReverseMapping();
    
        foreach (string s in result)
            Console.WriteLine(s);
    


    with an extension method:

        internal static string FormatReverseMapping(this IGrouping> grouping)
        {
            StringBuilder buffer = new StringBuilder();
    
            buffer.Append(grouping.Key);
            buffer.Append("=>");
            foreach (var x in grouping)
                buffer.Append(x.Key);
    
            return buffer.ToString();
        }
    

    Smiley

    (psst-- take a look at Systems.Collections.Generic.KeyValuePair.)

  • What's the functional programming / Linq form of this?

    Here's an alternative for deriving invert:

        var invert = from pair in data
                     group pair by pair.Value;
    


    Anyone know how to format this to "5=>a,e" etc. in a linq-esque fashion?


  • Trick or Treat?

    W3bbo wrote:
    Cute... but JPEG compression is your friend. Those images shouldn't be 600KB big.


    And... Jamie rebuts with a 1.2 MB image. Smiley



    Laser eyes dog is in ur bag
    stealin' ur treatz

  • Guys (Jamie?) where's the Channel9's Halloween decoration?

    jamie wrote:
    

     



    +1. [6]

  • Hi, I'm Chris and I am a VB.NET developer !

    W3bbo wrote:
    
    Maybe it's because you've gotta be pretty incompetant to be a VB.NET developer and not to be able to comprehend a C# example. A VB developer should know the few syntactical differences between C# and VB, because otherwise the languages share an identical paradigm.


    Is there a similar correlation for incompetent spellers? Expressionless

  • Date loop backwards

    ScanIAm wrote:
    If the compiler can figure out that I've got code that won't ever execute or notice that I'm comparing an int to a null, it should be able to find these conditions.


    The compiler doesn't know that in this case. All it knows is that you're ignoring the return value, which is a common idiom in code.

  • Date loop backwards

    DateTime is immutable. Instead of

    myDate.AddDays(-1)

    try

    myDate = myDate.AddDays(-1)





  • Employment.​End(me);

    I was laid off once. It was probably the best thing that could have happened to me at the time. I hope it turns out the same for you. Smiley

    Do you need to stay until Dec. 14th to get the 4 months of severance? Just something to consider. If you do stay, make yourself uber-useful and get a feel for whether they might be able to bring you back in on contract at a cushy rate. Cool

  • Cool It

    Minh wrote:
    What's the worse that can happen?

    As usual, reasonable people have reasonable answers.


    See this video on MSN Soapbox


    The action in the left column is the same for both rows, so the economic consequence should be roughly the same. Therefore, the lower left cell should also list global depression.

    If you accept that then there is only one cell that doesn't bring economic disaster. And potentially political suicide--you have to convince yourself that climate change is not coming in order to take the easy path, politically speaking.