Tips in VB.NET - Tip #6
In this tip we see about With....End With.
I know most of you atleast would have heard about With....End With block. But Most of us will not be using it.
I found it to be very useful.
With....End With
With...End statement is used to perform a series of statements on a specified object without requalifying the name of the object.
For example, to change a number of different properties/function on a single object, place the property assignment statements within the With...End With, referring to the object once instead of referring to it with each property assignment.
Now, lets modify the function which we defined in our Tip#3
Public Function ReturnDateInfoCollection() As System.Collections.Hashtable Dim ht As New Hashtable() ht.Add("Day", Format(DateTime.Today, "dddd")) ht.Add("Month", Month(DateTime.Today)) ht.Add("Hour", Hour(DateTime.Now)) ht.Add("Minute", Minute(DateTime.Now)) ht.Add("Second", Second(DateTime.Now)) Return ht End Function
Now, lets use the With....End With in the above function.
Public Function ReturnDateInfoCollection() As System.Collections.Hashtable Dim ht As New Hashtable() With ht .Add("Day", Format(DateTime.Today, "dddd")) .Add("Month", Month(DateTime.Today)) .Add("Hour", Hour(DateTime.Now)) .Add("Minute", Minute(DateTime.Now)) .Add("Second", Second(DateTime.Now)) End With Return ht End Function
I leave the remaing to you. There are many more things in this With...End With statement and they can be more useful to you. Explore and try to find some ways how you can make it more useful.
Please send me your suggestion and feedback to sadhasivam1981@yahoo.com.
Please vist http://sadhasivam.t35.com
Every Features has a purpose Finding it leads to great benefits
|
No responses found. Be the first to respond and make money from revenue sharing program.
|