Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6893159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:37:28+00:00 2026-05-27T06:37:28+00:00

The first compiles and runs . The second one fails because the method call

  • 0

The first compiles and runs . The second one fails because the method call returns an ICollection.

The following code works fine

foreach (XmlSchema schema in schemaSet.Schemas(targetNamespace)) 
{
    Id = schema.Id;
    Version = schema.Version;             
}

Since I am going to to get only one schema, why not go ahead and do this

XmlSchema schema = schemaSet.Schemas(targetNamespace);
Id = schema.Id;
Version = schema.Version;

There has to be something which is similar to the second one which will work?

How can this be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:37:29+00:00Added an answer on May 27, 2026 at 6:37 am

    You can use LINQ to make the second one work easily:

    XmlSchema schema = schemaSet.Schemas(targetNamespace).Cast<XmlSchema>().Single();
    Id = schema.Id;
    Version = schema.Version;
    

    If you’re definitely expecting only a single schema, I would definitely opt for using Single() instead of First() – that way if your expectations are ever mistaken, you’ll throw an exception rather than using whichever schema happened to come first out of the unexpectedly-large collection.

    The Cast<>() call is required because Schemas() only returns a weakly-typed ICollection rather than an implementation of IEnumerable<XmlSchema>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The example program below compiles two in-memory assemblies. The first compilation works fine. The
I have an iPhone app that compiles and runs fine in the Simulator on
Eclipse compiles and runs this jsp just fine but when I deploy to Sun
A CLI program of mine compiles and runs fine on windows. Compiles fine on
FIRST PROBLEM I have timed how long it takes to compute the following statements
Following some well-known OpenGL Haskell tutorial , I've made my first HOpenGL program. Here's
I had download and compiled the source code from GIT, and also successfully runs
How does the following code work even though the signature of the function in
First things first, I'm using cygwin version 1.7.1 on a Windows 7 box. Code
I have a make file of, more or less, the following structure that compiles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.