Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2007, 07:35 AM
Registered User
 
Join Date: Jun 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Optional prameters and C#?

Hi,

In the first chapter there is a metho with the signture
Public Shared Function GetContactsByFirstLetterAsCollection(ByVal DiaryId As Integer, Optional ByVal FirstLetterOfSurname As Char = "*") As ContactCollection

There is no such a behavior in C# so I have written
public static ContactCollection GetContactsByFirstLetterAsCollection(int diaryId, char FirstLetterOfSurname)
    {
        if (FirstLetterOfSurname == 0)
            FirstLetterOfSurname = '*';

I'm not sure that this is the best solution, any ideas?

 
Old August 5th, 2007, 11:07 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

IMO, it's cleaner to create an overload that calls the initial method passing in the default value. E.g.:

public static ContactCollection GetContactsByFirstLetterAsCollection(int diaryId)
{
  return GetContactsByFirstLetterAsCollection(diaryId, '*');
}

This way, calling code can skip the firstLetterOfSurname param by simply calling something like:

  GetContactsByFirstLetterAsCollection(5);

while you can still provide a firstLetterOfSurname by calling the other overload:

  GetContactsByFirstLetterAsCollection(5, 's');


Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 5th, 2007, 12:17 PM
Registered User
 
Join Date: Jun 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes it's better :) thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Argument not Optional aziaraphale Excel VBA 5 August 1st, 2007 02:53 AM
optional where in stored proc david_ste SQL Server ASP 2 October 27th, 2005 07:16 AM
Adding optional columns? shaileshmark SQL Server 2000 9 July 24th, 2004 03:57 PM
optional parameters in SP yuqlin BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 7 July 13th, 2004 03:28 PM
Optional WHERE clause in sproc KYC SQL Language 2 February 17th, 2004 03:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.