Where can I get the syntax, is there a comparison table? How do you do it?

Noah Aas 985 Reputation points
2024-05-10T14:25:15.3033333+00:00

Sample

IsValid callback;   // define a variable of delegate type IsValid
callback = s => s?.Length > 1;   // using lambda, define a callback function
var result = callback("test");   // invoke the callback code

IsValid callbackDelegateVariant2;
callbackDelegateVariant2 = Variant2_WriteWithDelegate;
var resultVariant2Delegate = callbackDelegateVariant2("test Variante2 withe delegate");   // invoke the callback code

private bool Variant2_WriteWithDelegate(string s)
{
	Trace.WriteLine(s);
	return s.Length > 1;
}

How do I come up with this spelling, what is the best way to go about it? Variant2 is clear.

var query = currentMappingTable.Labels.Label.Join(currentMappingTable.ParametersLabels.ParameterLabel, label => label.Id, parameter => parameter.FKParameter,
           (label, parameter) => new { label, parameter }).Join(currentMappingTable.Parameters.Parameter, label => label.parameter.FKLabel).where

Sometimes you can find (x,y) spellings. How do I find the correct syntax? Is there any good help? The advantage will be shorter spelling? Is that the case?

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2024-05-10T14:44:44.0266667+00:00

    Hi @Noah Aas , Welcome to Microsoft Q&A,

    To get the correct syntax for lambda expressions and LINQ queries in C#, you can refer to the official documentation or use code samples as references. Here are some resources where you can find syntax and examples:

    1. Official Microsoft Documentation:
    2. Online Tutorials and Blogs
    3. Books
    4. Development Environments:
      • IDEs like Visual Studio offer IntelliSense, which provides suggestions and autocompletion for syntax as you type.

    In C#, the (x, y) syntax you're referring to is called a lambda expression. It's a concise way to represent an anonymous function that can have one or more parameters. The syntax (x, y) => expression is used to define a lambda expression with parameters x and y.

    1. Use descriptive names: Name your methods and variables according to what they do or represent.
    2. Use camelCase for method names and local variables: This is a common convention in C#.
    3. Avoid abbreviations unless they're very common and won't confuse other developers.
    4. Be consistent: Once you choose a naming convention, stick to it.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.