471,315 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

String function not working while debugging.

Hi all,

I am facing some wierd problem in quick watch at a time of debugging
my application.

I have one variable of type string, say suppose i have code as below:

string FileName;
FileName = FileName.Substring(0,FileName.LastIndexOf("."));

At a time of debugging if i check value of filename it is displaying
value properly,

But when i try to add quick watch for expression
FileName.Substring(0,FileName.LastIndexOf(".")), it is giving me error
message that 'error: 'FileName.Substring' does not exist '

I don't know why this happening.

Or is it like that, i can't apply quick watch on string function while
debugging.

any help will be truely appreciated.

Thanks in advance.
Archana.

Feb 3 '06 #1
6 1687
I think it is like that only. Even you can't evaluate the functions of
int datatype.

Feb 3 '06 #2
Hi,
thanks for ur reply.

So means there is no other alternative to exeute function at runtime
other that storing value of those variables into variable and checking
value of that variable.

If u know any other alternative please tell me.

Thanks.

Feb 3 '06 #3
I could not figureout the exact way but, I created a simple class as
following

public class Test
{
public int i=10;

public int GetI()
{
return i;
}
}

I could execute GetI() function in debug mode. I think what we can
conclude from it is, the functions on the valuetypes can't be executed
in debug mode. I also tried to execute functions of hashtable in debug
mode and I got success.

Feb 3 '06 #4
Biren Prajapati <se*********@gmail.com> wrote:
I could not figureout the exact way but, I created a simple class as
following

public class Test
{
public int i=10;

public int GetI()
{
return i;
}
}

I could execute GetI() function in debug mode. I think what we can
conclude from it is, the functions on the valuetypes can't be executed
in debug mode. I also tried to execute functions of hashtable in debug
mode and I got success.


That wouldn't explain string not working for you, as string is a
reference type.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 3 '06 #5
I know string is a reference type but you would be knowing that string
is a special type which whenever assigned to another type of string
variable, the reference is not copied but another instance of that
string is created and copied into that string. Which is not the same in
other reference types.

Feb 7 '06 #6
Biren Prajapati wrote:
I know string is a reference type but you would be knowing that string
is a special type which whenever assigned to another type of string
variable, the reference is not copied but another instance of that
string is created and copied into that string. Which is not the same in
other reference types.


You're mistaken. No copy is made, and string acts like any other
reference type. It happens to be immutable, that's all. There are a few
ways in which String is special:

1) The CLR knows about it (for literals etc)
2) Literals are interned
3) The C# compiler handles concatenation using String.Concat
automatically.
4) There's a corner-case where calling the string constructor doesn't
actually create a new string (but only in a specific situation).

Other than that, it acts as any other reference type.

As String is immutable, it would be utter folly for a new instance to
be created every time the reference were assigned to another variable.
Here's a short but complete program which demonstrates that your claim
is incorrect:

using System;

class Test
{
static void Main()
{
// Avoiding using literal strings here just in
// case people think that's what's making it work...
string x = DateTime.Now.ToString();
string y = x;
Console.WriteLine (object.ReferenceEquals(x, y));
}
}

Jon

Feb 7 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by jdn | last post: by
2 posts views Thread by Andrew | last post: by
16 posts views Thread by BBM | last post: by
8 posts views Thread by bob | last post: by
14 posts views Thread by deko | last post: by
13 posts views Thread by Jennifer.Berube | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.