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. Equivalent C# 2.0 code

Equivalent C# 2.0 code

Scheduled Pinned Locked Moved C#
csharpjsonhelptutorial
2 Posts 2 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.
  • A Offline
    A Offline
    Ankit Rajpoot
    wrote on last edited by
    #1

    I cannot figure out how to translate the following line of code:

    int maxMagicBytesLength = imageFormatDecoders.Keys.OrderByDescending(x => x.Length).First().Length;

    into equivalent .Net 2.0 (C# 2.0) code. Here's the declaration of the imageFormatDecoders dictionary:

    private static Dictionary<byte[], Func<BinaryReader, Size>> imageFormatDecoders = new Dictionary<byte[], Func<BinaryReader, Size>>()
    {
    { new byte[] { 0x42, 0x4D }, DecodeBitmap },
    { new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }, DecodeGif },
    { new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }, DecodeGif },
    { new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng },
    { new byte[] { 0xff, 0xd8 }, DecodeJfif },
    };

    As my rest of the application is .net 2.0. I just can't figure out the use of the OrderByDescending() method. I've not worked in C# 3.0 or later versions. Please help me. Thanks in advance.

    Excuse me for buttin' in, but I'm interrupt driven.

    C 1 Reply Last reply
    0
    • A Ankit Rajpoot

      I cannot figure out how to translate the following line of code:

      int maxMagicBytesLength = imageFormatDecoders.Keys.OrderByDescending(x => x.Length).First().Length;

      into equivalent .Net 2.0 (C# 2.0) code. Here's the declaration of the imageFormatDecoders dictionary:

      private static Dictionary<byte[], Func<BinaryReader, Size>> imageFormatDecoders = new Dictionary<byte[], Func<BinaryReader, Size>>()
      {
      { new byte[] { 0x42, 0x4D }, DecodeBitmap },
      { new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }, DecodeGif },
      { new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }, DecodeGif },
      { new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng },
      { new byte[] { 0xff, 0xd8 }, DecodeJfif },
      };

      As my rest of the application is .net 2.0. I just can't figure out the use of the OrderByDescending() method. I've not worked in C# 3.0 or later versions. Please help me. Thanks in advance.

      Excuse me for buttin' in, but I'm interrupt driven.

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

      Ankit Rajpoot wrote:

      OrderByDescending(x => x.Length).First().Length;

      This code orders the collection from highest to lowest, based on the length, then grabs the first object. You could just iterate over the objects, and store the highest length.

      Christian Graus Driven to the arms of OSX by Vista. Please read this[^] if you don't like the answer I gave to your question. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.

      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