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

  • Thread starter Mickey Williams [C# MVP]
  • Start date
G

Guest

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.
 
G

Guest

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
}
 
J

Jon Skeet [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top