-
"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.
-
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!
-
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".
-
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?
-
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"
Similar Threads
-
By mycwcgr in forum ASP.NET
Replies: 1
Last Post: 08-31-2005, 01:21 AM
-
By Sridhar Mahadevan in forum .NET
Replies: 6
Last Post: 10-02-2002, 05:59 PM
-
By Louis-Philippe Carignan in forum .NET
Replies: 2
Last Post: 02-18-2002, 03:16 PM
-
By Larry Serflaten in forum .NET
Replies: 64
Last Post: 06-22-2001, 08:00 PM
-
By Will Storer in forum VB Classic
Replies: 1
Last Post: 04-19-2000, 04:27 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks