Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Default value (null) for int data
Message
 
 
To
07/04/2008 13:48:06
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01308785
Message ID:
01308792
Views:
9
>>Hi everybody,
>>
>>I have the following method signature:
>>
>> public List<MembershipUserWrapperForMP> GetMembers(bool approvalStatus, string sortData, string ExcludeRole, int SiteID)
>>
>>I want to be able to call it without 3 last parameters (they should be optional).
>>
>>However, this declaration:
>>
>>
>>[DataObjectMethod(DataObjectMethodType.Select, false)]
>>        public List<MembershipUserWrapperForMP> GetMembers()
>>        {
>>            return GetMembers(true, true, null, null, null, null);
>>        }
>>
>>produces the following error:
>>Error 103 Argument '6': cannot convert from '' to 'int' C:\Development\Visual Studio 2005\WebSites\FCAdmin\App_Code\MembershipUserAndProfileODS.cs 160 61 C:\...\FCAdmin\
>>
>>
>>There is not that much help in MS Help on this error.
>>
>>Could you please tell me what should I use if I want to have optional integer parameter?
>>
>>Thanks a lot in advance.
>
>__
>Nadya,
>
>I think you'll have to overload it, ie provide same method with different signature
>
>
>public List<MembershipUserWrapperForMP> GetMembers(bool approvalStatus, string sortData, string ExcludeRole, int SiteID)
>{
>// you will have to test for (sortData==null), etc
>....
>}
>
>public List<MembershipUserWrapperForMP> GetMembers(bool approvalStatus)
>{
>   return GetMembers(bool approvalStatus, null, null, 0)  && or -1
>}
>
Here is what compiles:

return GetMembers(true, true, null, null, null, System.Convert.ToInt32(null) );

I'm not sure if this is correct and if my check in the code

if (SiteID == null || md.SiteID == SiteID )
memberList.Add(md);

is correct now.

For strings null works great, but what should I use for integers? I may use some arbitrary number as default, say, -3200000, but is it correct?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform