简体   繁体   中英

Translate vb.net to C#: one line of code

This link offers sample code to infer the schema of an XML file, in VB.NET. One particular line fails in my translation to C#, namely,

Dim schema As XmlSchema = schemaSet.Schemas()(0)

My translation is

XmlSchema schema = schemaSet.Schemas()[0];

I cannot see what is wrong with my translation?

XmlSchemaSet.Schemas() returns an ICollection which you can't access by index. If you use use .NET 3.5 you can use Linq to do:

schemaSet.Schemas().Cast<XmlSchema>().First();

Otherwise you have to use a foreach loop and stop after the first iteration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM