Re: new to C# 'string' does not contain a definition for 'length'

  • Thread starter Thread starter Mickey Williams [C# MVP]
  • Start date Start date
Thank you. Now I get the error

The name 'Substring' does not exist in the class or namespace
'ASP.WebForm1_aspx'

I hope this one is just as easy!! Thanks.
 
It should be. Try StoreUser.SubString( <starting index>, <length>). However
this will throw an exception if your database sets the variable as a
zero-length string (null or blank)

You can get around it with an expression like this:

If (StoreUser.Length >= 3)
{
//run your logic
}
 
AshleyT said:
Thank you. Now I get the error

The name 'Substring' does not exist in the class or namespace
'ASP.WebForm1_aspx'

I hope this one is just as easy!! Thanks.

Yup, you want StoreUser.Substring, not just Substring - otherwise it
doesn't know what you're trying to take a substring of.

I think you'd be better learning "plain" C# outside the ASP.NET context
to start with, to be honest - it's easier if you only have C# syntax to
learn about rather than the ASP.NET tags as well. I'd start with simple
console apps, then learn about file IO and collections, then possibly
move onto databases, then go onto ASP.NET.
 
Back
Top