Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
public static string dbFilePath = dataFolder + "\\database.mdf;;
static string Security = ";Integrated Security=True;
static string Datasource = @"Data Source=(LocalDB
\v11.0;AttachDbFilename=";

public static string connectionstring = Datasource + dbFilePath + Security;
public static LinqToSqlDataContext dc = new LinqToSqlDataContext( connectionstring );





private static int PhotoId()
{
while (true)
{
int n = new Random().Next( 9999 );
if (!dc.ROOMPHOTOs.Select( c => c.Number ).Contains( n ))
return n;
}
}
dc is link
i dont understand this statment (c => c.Number).
Posted

ROOMPHOTOs is collection of some type, we don't know what so let's say MyType, so it will be something like

List<mytype>

ROOMPHOTOs.Select( c => c.Number )


The Select statement is going to run the code inside the brackets for each item in ROOMPHOTOs, where the item is going to be referred to as "c" so, so c.Number means "the Number property of each MyType in the ROOMPHOTOs collection".

Select outputs a collection itself, and everything in the ( ) is what becomes the new collection. So Select(c => c.Number) is going to return a collection of whatever type Number is. If Number is int then Select will return IEnumerable<int> which will reference a list of all the Number properties of all the MyType items in your ROOMPHOTOs collection.

.Contains(n) will return true if any item in the collection (it is acting on the Select so the IEnumerable<int> list of all the Number properties) matches n. So the code is similar in function to this

foreach (MyType c in ROOMPHOTOs)
{
    if (c.Number == n)
    {
        return true;
    }
}
 
Share this answer
 
That is a lambda expression. it can be explained as looping through ROOMPHOTOs
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900