DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5

Thread: "With" Keyword

  1. #1
    Join Date
    Dec 2004
    Posts
    717

    "With" Keyword

    Could anyone please tell me which keyword can we use in C# as like as "With" keyword in vb.NET?
    I think no keyword like that..
    thanks.

    Any help would be appreciated.
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    There is no equivalent to VB's With keyword in C#.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jul 2004
    Posts
    81
    If your main incentive for using "With" in VB was to save typing, then you can accomplish something similar by assigning to an abbreviated variable:

    VB:
    With LongNameYouDontWantToRetype
    .a...
    .b...
    End With

    C#:
    SomeType o = LongNameYouDontWantToRetype
    o.a...
    o.b...

    I personally don't do this, but it accomplishes the same goal as "With".
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  4. #4
    Join Date
    Dec 2004
    Posts
    717
    Thanks. David & Phil.

    Hi David,

    Suppose:
    I would like to write like that.
    Dim objCandidatePersonalInformations as New CandidatePersonalInformations
    With objCandidatePersonalInformations
    .FirstName = "Michael"
    .LastName = "Sync"
    End
    As u said,
    CandidatePersonalInformations objCandidatePersonalInformations = New CandidatePersonalInformations();

    xxxType o = objCandidatePersonalInformations;

    o.FirstName="Michael"
    o.LastName="Sync"
    Is it what you meant?
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  5. #5
    Join Date
    Jul 2004
    Posts
    81
    Yes, but the type of the abbreviated variable has to be the same.
    Note that I don't code like this - just offering something that performs a similar function to VB's "With".

    CandidatePersonalInformations objCandidatePersonalInformations = New CandidatePersonalInformations();

    ...

    CandidatePersonalInformations o = objCandidatePersonalInformations;

    o.FirstName="Michael"
    o.LastName="Sync"
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

Similar Threads

  1. Replies: 1
    Last Post: 08-31-2005, 01:21 AM
  2. The 'internal' keyword.
    By Sridhar Mahadevan in forum .NET
    Replies: 6
    Last Post: 10-02-2002, 05:59 PM
  3. Sealing methods must include the override keyword, why ?
    By Louis-Philippe Carignan in forum .NET
    Replies: 2
    Last Post: 02-18-2002, 03:16 PM
  4. Rehashing NEW keyword a SECOND time, right NOW...
    By Larry Serflaten in forum .NET
    Replies: 64
    Last Post: 06-22-2001, 08:00 PM
  5. multiple keyword search to display to data grid control
    By Will Storer in forum VB Classic
    Replies: 1
    Last Post: 04-19-2000, 04:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links