Showing posts with label empty. Show all posts
Showing posts with label empty. Show all posts

Wednesday, March 28, 2012

String.Empty or string.Empty

Howdie y'all,

Can somebody just tell me what's the difference between String.Empty and string.Empty

I use C# in VWD and the 'String' shows up green and the 'string' shows up blue.

Thanks,

Wes

String (with a big S) is actually the System.String class from the Framework Class Library. string (with a small s) is the C# keyword alias for the System.String class, which is why it is blue. There is no difference in their use, other than the case of the S, and the compiler generates identical code in both cases. This is one of the very few cases in C# where case doesn't matter.

I've seen coding standards that mandate the use of the Framework type names (e.g. Int32 rather than C#'s int). In some cases this is because there are methods on types, such as ToInt32(), but I'm ambivalent to this as an argument.


Short and clear!!!

Thanks a lot(I don't have to redo my code now)...

Wes

P.S. what do you use as Standard?


I tend to favour the coding standard as offered by Juval Lowy, as found athttp://www.idesign.net


Lance Hunt's coding standards also recommends using the language alias versus the .NET type, i.e., string vs. String

http://weblogs.asp.net/lhunt/archive/2004/08/17/CSharpCodingStandardsv113.aspx

but still the question remains... why?

string.lenght vs string.empty

Hi,
I read that to check for empty strings , comparing strings using
String.Length == 0 is faster than String.Empty or "" . Is it true...?
If so, how?AVL wrote:
> Hi,
> I read that to check for empty strings , comparing strings using
> String.Length == 0 is faster than String.Empty or "" . Is it true...?
> If so, how?

I think it is faster because:
* Length is stored, doesn't need to be calculated
* integer comparison (Length == 0) is easier that string comparison,
which (I think) needs to be done on a character-by-character basis.

Hans Kesting
On Wed, 27 Apr 2005 22:46:02 -0700 in
microsoft.public.dotnet.framework.aspnet, AVL
<AVL@.discussions.microsoft.com> wrote:

>Hi,
> I read that to check for empty strings , comparing strings using
>String.Length == 0 is faster than String.Empty or "" . Is it true...?
>If so, how?

I think str.Length is probably faster, however if your string is null,
using Length will throw a NRE. I prefer to use
string.IsNullOrEmpty(someString). It safely works on null strings as
well as empty strings.

Roger
Under normal circumstances it's unlikely to give a perceptible difference...

You could easily measure and see what the IL is...

Patrice

--

"AVL" <AVL@.discussions.microsoft.com> a crit dans le message de
news:1F293E96-5693-4438-A520-B18BB5FF356C@.microsoft.com...
> Hi,
> I read that to check for empty strings , comparing strings using
> String.Length == 0 is faster than String.Empty or "" . Is it true...?
> If so, how?
It is true that checking the String.Length is faster.
Numeric functions are almost always more efficient than string functions.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"AVL" <AVL@.discussions.microsoft.com> wrote in message
news:1F293E96-5693-4438-A520-B18BB5FF356C@.microsoft.com...
> Hi,
> I read that to check for empty strings , comparing strings using
> String.Length == 0 is faster than String.Empty or "" . Is it true...?
> If so, how?

string.lenght vs string.empty

Hi,
I read that to check for empty strings , comparing strings using
String.Length == 0 is faster than String.Empty or "" . Is it true...?
If so, how?AVL wrote:
> Hi,
> I read that to check for empty strings , comparing strings using
> String.Length == 0 is faster than String.Empty or "" . Is it true...?
> If so, how?
I think it is faster because:
* Length is stored, doesn't need to be calculated
* integer comparison (Length == 0) is easier that string comparison,
which (I think) needs to be done on a character-by-character basis.
Hans Kesting
On Wed, 27 Apr 2005 22:46:02 -0700 in
microsoft.public.dotnet.framework.aspnet, AVL
<AVL@.discussions.microsoft.com> wrote:

>Hi,
> I read that to check for empty strings , comparing strings using
>String.Length == 0 is faster than String.Empty or "" . Is it true...?
>If so, how?
I think str.Length is probably faster, however if your string is null,
using Length will throw a NRE. I prefer to use
string.IsNullOrEmpty(someString). It safely works on null strings as
well as empty strings.
Roger
Under normal circumstances it's unlikely to give a perceptible difference...
You could easily measure and see what the IL is...
Patrice
"AVL" <AVL@.discussions.microsoft.com> a crit dans le message de
news:1F293E96-5693-4438-A520-B18BB5FF356C@.microsoft.com...
> Hi,
> I read that to check for empty strings , comparing strings using
> String.Length == 0 is faster than String.Empty or "" . Is it true...?
> If so, how?
It is true that checking the String.Length is faster.
Numeric functions are almost always more efficient than string functions.
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"AVL" <AVL@.discussions.microsoft.com> wrote in message
news:1F293E96-5693-4438-A520-B18BB5FF356C@.microsoft.com...
> Hi,
> I read that to check for empty strings , comparing strings using
> String.Length == 0 is faster than String.Empty or "" . Is it true...?
> If so, how?

Saturday, March 24, 2012

StringWriter object and dispose method

Re hello,
I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to export
in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :
example :
Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing
BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
As Boolean)' is not accessible in that context. it is protected..
I can use the Close() method but i m not sure that this last one have the
same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object
Thanks for you help
fabriceUse Close(). Setting the objec to null stops the object from being
referenced, so the GC will clear it out when it's ready. Note that Dispose
DOES not remove the object from memory.
http://msdn.microsoft.com/msdnmag/issues/1100/gci/
"fabrice" <emouchet@.test.com> wrote in message
news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...
> Re hello,
> I m' sorry for my questions ..
> Under framework 1.1 with vb.net, i m using a StringWriter object to export
> in .xls file.
> To empty memory, I would like to use the propterty dispose on the object
> StringWriter.
> But i have received an error like this :
> example :
> Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
> ...
> myStringWriter.Dispose(System.Boolean)(true)
> myStringWriter=Nothing
>
> BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
> As Boolean)' is not accessible in that context. it is protected..
>
> I can use the Close() method but i m not sure that this last one have the
> same effects for Garbage Collector ?
> Is it possible to use Dispose method with StringWriter object
>
> Thanks for you help
> fabrice
>
Great.
Thanks for you help.
have a nice day
"Dan Bass" <na> a crit dans le message de news:
%23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...
> Use Close(). Setting the objec to null stops the object from being
> referenced, so the GC will clear it out when it's ready. Note that Dispose
> DOES not remove the object from memory.
> http://msdn.microsoft.com/msdnmag/issues/1100/gci/
>
> "fabrice" <emouchet@.test.com> wrote in message
> news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...
>
remember that you also don't need <myObject> = Nothing explicitly in order
for the GC to clean the object up, although it is (IMO) good coding
practice.
"fabrice" <emouchet@.test.com> wrote in message
news:ewVgTr$BHHA.4928@.TK2MSFTNGP02.phx.gbl...
> Great.
> Thanks for you help.
> have a nice day
> "Dan Bass" <na> a crit dans le message de news:
> %23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...
>
Thanks Dan.
"Dan Bass" <na> a crit dans le message de news:
OgD8SCACHHA.3380@.TK2MSFTNGP04.phx.gbl...
> remember that you also don't need <myObject> = Nothing explicitly in order
> for the GC to clean the object up, although it is (IMO) good coding
> practice.
> "fabrice" <emouchet@.test.com> wrote in message
> news:ewVgTr$BHHA.4928@.TK2MSFTNGP02.phx.gbl...
>

StringWriter object and dispose method

Re hello,

I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to export
in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :

example :

Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing

Quote:

Originally Posted by

Quote:

Originally Posted by

>Error


BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
As Boolean)' is not accessible in that context. it is protected..

I can use the Close() method but i m not sure that this last one have the
same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object

Thanks for you help
fabriceUse Close(). Setting the objec to null stops the object from being
referenced, so the GC will clear it out when it's ready. Note that Dispose
DOES not remove the object from memory.

http://msdn.microsoft.com/msdnmag/issues/1100/gci/
"fabrice" <emouchet@.test.comwrote in message
news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Re hello,
>
I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to export
in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :
>
example :
>
Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing
>

Quote:

Originally Posted by

Quote:

Originally Posted by

>>Error


>
BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
As Boolean)' is not accessible in that context. it is protected..
>
>
I can use the Close() method but i m not sure that this last one have the
same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object
>
>
Thanks for you help
fabrice
>


Great.
Thanks for you help.
have a nice day

"Dan Bass" <naa crit dans le message de news:
%23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>
Use Close(). Setting the objec to null stops the object from being
referenced, so the GC will clear it out when it's ready. Note that Dispose
DOES not remove the object from memory.
>
http://msdn.microsoft.com/msdnmag/issues/1100/gci/
>
>
>
"fabrice" <emouchet@.test.comwrote in message
news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>Re hello,
>>
>I m' sorry for my questions ..
>Under framework 1.1 with vb.net, i m using a StringWriter object to
>export in .xls file.
>To empty memory, I would like to use the propterty dispose on the object
>StringWriter.
>But i have received an error like this :
>>
>example :
>>
>Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
>...
>myStringWriter.Dispose(System.Boolean)(true)
>myStringWriter=Nothing
>>

Quote:

Originally Posted by

>>>Error


>>
>BC30390: 'System.IO.StringWriter.Protected Overrides Sub
>Dispose(disposing As Boolean)' is not accessible in that context. it is
>protected..
>>
>>
>I can use the Close() method but i m not sure that this last one have the
>same effects for Garbage Collector ?
>Is it possible to use Dispose method with StringWriter object
>>
>>
>Thanks for you help
>fabrice
>>


>
>


remember that you also don't need <myObject= Nothing explicitly in order
for the GC to clean the object up, although it is (IMO) good coding
practice.

"fabrice" <emouchet@.test.comwrote in message
news:ewVgTr$BHHA.4928@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Great.
Thanks for you help.
have a nice day
>
"Dan Bass" <naa crit dans le message de news:
%23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>>
>Use Close(). Setting the objec to null stops the object from being
>referenced, so the GC will clear it out when it's ready. Note that
>Dispose DOES not remove the object from memory.
>>
>http://msdn.microsoft.com/msdnmag/issues/1100/gci/
>>
>>
>>
>"fabrice" <emouchet@.test.comwrote in message
>news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>>Re hello,
>>>
>>I m' sorry for my questions ..
>>Under framework 1.1 with vb.net, i m using a StringWriter object to
>>export in .xls file.
>>To empty memory, I would like to use the propterty dispose on the object
>>StringWriter.
>>But i have received an error like this :
>>>
>>example :
>>>
>>Dim myStringWriter As System.IO.StringWriter = New
>>System.IO.StringWriter
>>...
>>myStringWriter.Dispose(System.Boolean)(true)
>>myStringWriter=Nothing
>>>
>>>>Error
>>>
>>BC30390: 'System.IO.StringWriter.Protected Overrides Sub
>>Dispose(disposing As Boolean)' is not accessible in that context. it is
>>protected..
>>>
>>>
>>I can use the Close() method but i m not sure that this last one have
>>the same effects for Garbage Collector ?
>>Is it possible to use Dispose method with StringWriter object
>>>
>>>
>>Thanks for you help
>>fabrice
>>>


>>
>>


>
>


Thanks Dan.

"Dan Bass" <naa crit dans le message de news:
OgD8SCACHHA.3380@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

remember that you also don't need <myObject= Nothing explicitly in order
for the GC to clean the object up, although it is (IMO) good coding
practice.
>
"fabrice" <emouchet@.test.comwrote in message
news:ewVgTr$BHHA.4928@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>Great.
>Thanks for you help.
>have a nice day
>>
>"Dan Bass" <naa crit dans le message de news:
>%23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>>>
>>Use Close(). Setting the objec to null stops the object from being
>>referenced, so the GC will clear it out when it's ready. Note that
>>Dispose DOES not remove the object from memory.
>>>
>>http://msdn.microsoft.com/msdnmag/issues/1100/gci/
>>>
>>>
>>>
>>"fabrice" <emouchet@.test.comwrote in message
>>news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...
>>>Re hello,
>>>>
>>>I m' sorry for my questions ..
>>>Under framework 1.1 with vb.net, i m using a StringWriter object to
>>>export in .xls file.
>>>To empty memory, I would like to use the propterty dispose on the
>>>object StringWriter.
>>>But i have received an error like this :
>>>>
>>>example :
>>>>
>>>Dim myStringWriter As System.IO.StringWriter = New
>>>System.IO.StringWriter
>>>...
>>>myStringWriter.Dispose(System.Boolean)(true)
>>>myStringWriter=Nothing
>>>>
>>>>>Error
>>>>
>>>BC30390: 'System.IO.StringWriter.Protected Overrides Sub
>>>Dispose(disposing As Boolean)' is not accessible in that context. it is
>>>protected..
>>>>
>>>>
>>>I can use the Close() method but i m not sure that this last one have
>>>the same effects for Garbage Collector ?
>>>Is it possible to use Dispose method with StringWriter object
>>>>
>>>>
>>>Thanks for you help
>>>fabrice
>>>>
>>>
>>>


>>
>>


>
>

Tuesday, March 13, 2012

stuck on empty page after sending email with.........mailto:"email address here"

Hi, i have code that opens an Ms outlook new email message window on myGridviews' ItemUpdated event. I did this because of the easy with which users will find email addresses to send messages to with out the pain of remembering or cramming the so many company employee email accounts. After sending the email, outlook closes which is okay to me but the problem is, i now remain with a blank page instead of returning to the page with my Gridview from where i fired the update event that opened outlook. I wish i had away of posting or redirecting to another page or even better returning to the same page from ItemUpdated event that opened outlook was fired from. Iam not sure if this explaination is clear to any one reading it but below is the code iam talking about.

ProtectedSub GridView1_RowUpdated(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.GridViewUpdatedEventArgs

Response.Redirect(mailto:my-email-account@dotnet.itags.org.ppp.co.ug

Response.redirect("Default.aspx") 'Why is this line of code not redirecting to Default.aspx

END SUb

Option Two: How can i open outlook when an event fires without using Response.Redirect because that is exactly what what is bringing me all this mess.

Dont use a Response.Redirect(), just use an HREF...


Your first response.redirect changes the page you are on, so the second one never fires.

Why not just show the email address when your user updates the row? Or use a pop-up to display the email address for the user to click.

Try creating a hidden iframe and setting the location of the iframe to the mailto address. This might do the trick, but I haven't tested it.

--JJ


This is my scenerio. when a row is updated, basically we are talking about a name field which is initially null being filled with an employee name. So when the user clicks update after typing the employee name in this field, On the itemUpdate event of this particular Gridview, outlook opens and then the administrator doing the update should lookup the email address in outlook of the same employee whose name was entererd prevously. The aim is to send a notification email that he has been assigned a record he/she should take charge of.

So at the end of the operation, a record should have been updated and an outlook email(not automatic) should have been send to the employee whose name was entered in the Gridviews' name field.


How do you use HREF in an event handle sub procedure.


By HREF, Curt means a HyperLink. You need to use a hyperlink and open a popup to send the mail

<a href="http://links.10026.com/?link=my-email-account@.ppp.co.ug" target="_blank">Send Mail</a>

Thanks