473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How FirstOrDefault function works?

6
Hi all,
Im new in coding and i need to change something a code that i barely understand. And the problem is a FirstOrDefalut function.
Below is the code.
Expand|Select|Wrap|Line Numbers
  1. public static string GetArticlePageUrl(Article article, int categoryId)
  2.     {
  3.  
  4.         if (categoryId < 0)
  5.         {
  6.             ArticleCategoryLink acl = article.ArticleCategoryLinks.FirstOrDefault();
  7.  
  8.             if (acl != null && acl.Category != null)
  9.                 categoryId = acl.Category.ID;
  10.         }
  11.  
  12.         if (categoryId > 0)
  13.             retVal = retVal + string.Format("&cid={0}", categoryId);
  14.  
  15.         return retVal;
  16.     }
  17.  
  18.  
  19.  
I just want to change
Expand|Select|Wrap|Line Numbers
  1. ArticleCategoryLink acl = article.ArticleCategoryLinks.FirstOrDefault();
whitch now get the first or default categoryid among the categories that the article belongs, to get the second value, or the first among some certain values that i can give, or the first among all excluding some values that i ll give.

Im sorry if its Code is messy, or if i missed to give any info. i just dont know what i should post to help you giving me an answer.

Thank you in advance.
Jan 27 '11 #1
1 2501
Markus
6,050 Expert 4TB
You haven't explained your question very well. Give it another try. Also, how can we help if we cannot see the method-in-question's code? Post the code for FirstOrDefault().
Jan 28 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: atomo | last post by:
Hi, i'm wondering why this hiding and showing function works on IE (6) but it doesn't work in Mozilla Firebird (0.7) function fnc_show(num){ for(i=1;i<7;i++){ eval("t_" + i + ".style.display...
6
by: Martin Holmgaard | last post by:
I have written the following function to be used for flood filling in a bitmap. The function works fine on Windows XP Prof and Windows 2000 server, but on Windows 2003 server it return a stack...
18
by: James Radke | last post by:
Hello, We are currently using a user DLL that when working in VB 6.0 has a user defined type as a parameter. Now we are trying to use the same DLL from a vb.net application and are having...
2
by: Armin | last post by:
Hello I want get the Screen Coordinates of a Control. I do this with Control.PointToScreen. vlob_Point = Me.PointToScreen(New System.Drawing.Point(0, 0)) This works fine with a Single...
4
by: kongkolvyu | last post by:
Hi The strptime function works just fine on Solaris. Here is an example on how I use it: struct tm tmpTm; if(strptime("20010101010101","%Y%m%d%H%M%S",&tmpTm)==NULL) printf("Error,String convert...
0
by: Crystal | last post by:
I have created a small program that prints out an organization chart in PHP using the GD lib's imagecreate, imageline and imagestring functions. Basically, a user selects an employee from a...
3
by: Bob | last post by:
I have a small JS function to edit "code". This function works as intended in Firefox, but not IE 6 or Opera 9. I suppose this is an old story, but is there a work around? I have two forms on the...
5
by: jonavanmona | last post by:
Hi, maybe a piec of cake for more educated Js-peeps, but here's the prob: function: function schrijfopt(wat, waarde, waar){ var url = 'edit2.php'; var pars = "wijzig=fg";
0
by: Chris | last post by:
I have a list and it's rowsourcetype is set to the function get_databases_DIR. Function works without any problem in MDB, but not in MDE (nothing is returned). If Static was the problem, since I am...
1
by: pilafi | last post by:
void CSVImageIO::Read( void * buffer) { char onedataline; char *tmp=0; double d=0; unsigned short data=0; unsigned short * inptr = static_cast< unsigned short * >( buffer ); unsigned...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.