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 6255471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:22:18+00:00 2026-05-24T14:22:18+00:00

i went over some questions and searched google a bit, but i couldnt find

  • 0

i went over some questions and searched google a bit,
but i couldnt find an answer ( That satisfies me ).

Basicly, i understand the SingleOrDefault return null or 0 ( depends on the type ).

but how can i make it return something else ?

return myChannels.All.Where(_Channel => _Channel.Guid == this.ParentChannelGuid).SingleOrDefault(_SPECIFICCHANNEL);

so, i want _SPECIFICCHANNEL to be returned in case it is not single..
can that 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-24T14:22:19+00:00Added an answer on May 24, 2026 at 2:22 pm

    This can be accomplished in a rather simple way. If you create your own extension method that is more specific than the generic SingleOrDefault, then the compiler will prefer the more type-specific version. Here’s an example that shows how to do that with a simple Person class (you can copy-paste it into LINQPad to quickly see the result):

    public class Person
    {
        public string Name { get; set; }
    
        public override string ToString()
        {
            return Name ?? "";
        }
    }
    
    public static class PersonExtensionMethod
    {
        public static Person SingleOrDefault(this IEnumerable<Person> source)
        {
            var person = Enumerable.SingleOrDefault(source);
    
            if (person == null)
                return new Person { Name = "Unnamed" };
    
            return person;
        }
    }
    
    public static void Main()
    {
        var emptyCollection = new Person[0];
        var nonEmptyCollection = new Person[] { new Person { Name = "Jack" } };
    
        Debug.WriteLine("Empty collection: " + emptyCollection.SingleOrDefault());
        Debug.WriteLine("Non-empty collection: " + nonEmptyCollection.SingleOrDefault());
    }
    

    In the above example, SingleOrDefault(IEnumerable<Person>), takes precedence over SingleOrDefault<T>(IEnumerable<T>) which is less specific.

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

Sidebar

Related Questions

I've counted, checked my commas, and went over the whole thing again but I
I went as far as searching C sources, but I can't find this function,
in class we went over the subset_of/2 predicate that my teacher gave as follows:
Re-Edited: I went over to W3schools and played around in there javascript editor window
I went to download SharpZipLib assemblies but it looks like its not on SourceForge.
I went through a document at Adobe Livedocs that describes working with pdf: http://livedocs.adobe.com/flex/3/html/help.html?content=PDF_1.html
I went through some tutorials on the State monad and I think I got
I went over making my own copy constructor and it overall makes sense to
I am a perl developer that has never went into the client side programming
Some newbie questions about multi-threading in .NET which I think will help reinforce some

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.