Web Log di Adrian Florea

"You know you've achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away." Antoine de Saint-Exupery
posts - 440, comments - 2715, trackbacks - 3944

My Links

Archives

Post Categories

Image Galleries

.RO Blogs

.RO People

.RO Sites

Blogs

Furls

Links

vinCitori

Quiz Sharp #49

I seguenti due snippet si compilano con le stesse opzioni, però il codice IL generato per i due foreach, come struttura, è ben diverso:


using System;
using System.Management;

class Foo
{
  static void Main()
  {
    foreach (ManagementObject device in new ManagementClass("Win32_LogicalDisk").GetInstances())
    {
      Console.WriteLine(device["deviceid"]);
    }
  }
}

using System;
using System.Xml;
using System.Xml.Schema;

class Foo
{
  static void Main()
  {
    string xsd = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
      "\\Microsoft Visual Studio .NET 2003\\Common7\\Packages\\schemas\\xml\\asp.xsd";
    XmlTextReader reader = new XmlTextReader(xsd);
    foreach(XmlSchemaObject schemaObj in XmlSchema.Read(reader, null).Items)
    {
      Console.WriteLine(schemaObj.LineNumber);
    }
    reader.Close();
  }
}

Offrite una spiegazione.

Print | posted on lunedì 2 maggio 2005 19:34 | Filed Under [ Quiz Sharp ]

Powered by:
Powered By Subtext Powered By ASP.NET