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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:04:28+00:00 2026-06-03T21:04:28+00:00

This fails string temp = () => {return test;}; with the error Cannot convert

  • 0

This fails

string temp = () => {return "test";};

with the error

Cannot convert lambda expression to type ‘string’ because it is not a delegate type

What does the error mean and how can I resolve it?

  • 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-06-03T21:04:29+00:00Added an answer on June 3, 2026 at 9:04 pm

    The problem here is that you’ve defined an anonymous method which returns a string but are trying to assign it directly to a string. It’s an expression which when invoked produces a string it’s not directly a string. It needs to be assigned to a compatible delegate type. In this case the easiest choice is Func<string>

    Func<string> temp = () => {return "test";};
    

    This can be done in one line by a bit of casting or using the delegate constructor to establish the type of the lambda followed by an invocation.

    string temp = ((Func<string>)(() => { return "test"; }))();
    string temp = new Func<string>(() => { return "test"; })();
    

    Note: Both samples could be shorted to the expression form which lacks the { return ... }

    Func<string> temp = () => "test";
    string temp = ((Func<string>)(() => "test"))();
    string temp = new Func<string>(() => "test")();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Foo(bar: String) { import Foo.Bar def this() = this(Bar) // this line fails,
This fails on VS2010 RC LINQ-to-SQL with the InvalidOperationException Stored procedures cannot be used
short s; s = (EitherTrueOrFalse()) ? 0 : 1; This fails with: error CS0266:
For some reason, this MySQL fails: CREATE SCHEMA IF NOT EXISTS `partB` DEFAULT CHARACTER
In PowerShell I have tried: alias | select-string Alias This fails even though Alias
Does anyone know why this fails to compile? type MyInterface<'input, 'output> = abstract member
Can't for the life of me understand why this fails: #include <vector> #include boost/algorithm/string/predicate.hpp
I have this code: FVDTO.setStatus(fail); List<String[]> invalidFields = new ArrayList<String[]>(); Iterator<ConstraintViolation<HazardSubmission>> iterator = cv.iterator();
This fails: my @a = (a, b, c, d, e); my %h = map
This works under the .net framework 3.5 client. This fails under the .net framework

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.