By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,855 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,855 IT Pros & Developers. It's quick & easy.

String function not working while debugging.

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
I think it is like that only. Even you can't evaluate the functions of
int datatype.

Feb 3 '06 #2

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.