Using Len in C#

S

sck10

Hello,

I am trying to find the equivalent of LEN in C#:
if (Len(this.ddlAudioDate.SelectedItem.Text) != 0)

Any help would be appreciated.

Thanks, sck10
 
B

bruce barker \(sqlwork.com\)

string s = "hello";

if (s.Length > 0)
{
// do something
}

-- bruce (sqlwork.com)
 
G

Guest

Also in addition you still can use VB.NET Functions:
1)Add reference to Microsoft.VisualBasic Assembly "Microsoft.VisualBasic.dll"
2)Add "using" statement for namespace(s) you wish to use from
Microsoft.VisualBasic for example : "using Microsoft.VisualBasic"
3)you can find the functions you want inside modules and classes defined in
the namesapce(s) like Strings and Constants Modules
4) to use Len Call Strings.Len(YourVariable);
For more information review Microsoft.VisualBasic Namspace in MSDN

Regards
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
 
M

msnews.microsoft.com

int len = this.ddlAudioDate.SelectedItem.Text.Length;

It is a string, no? :)

if(len != 0)
{
}

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think Outside the Box!
*************************************************
 
C

CyberSpy

Muhammed,

You are right in that you CAN use this method, but why would you want
to, when these tools are all available natively in C#. What's the point
of learning a new (and far better IMHO) language, to step back in time
to these old constructs from another laguage as soon as something is
not obvious?

Regards

Adam
 
M

Mark Rae

You are right in that you CAN use this method, but why would you want
to, when these tools are all available natively in C#. What's the point
of learning a new (and far better IMHO) language, to step back in time
to these old constructs from another laguage as soon as something is
not obvious?

I couldn't agree more! There is no reason whatsoever (other than sheer
laziness) to use the VB assembly...
 
G

Guest

Yes may be you are right, but in sometimes someone wants to use some VB.NET
fast out of the box Functionalities like Financials, FileIO. Also in Strings
there are some useful functions like RIGHT which is not availabe in string
class
Even I don't usually use it, but I see it as useful feature.
It is still something we should know, to use it or not, it is up to everyone
needs
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
 
C

CyberSpy

Muhammed,

With components like Financials, I'm sure there are equivalent (or
newer/better) versions that can be found for the rare occasions it's
needed.

RIGHT is very easy to replicate:
string test = "abcdefghijklmnopqrstuvwxyz";
// Get the right most 10 chars
string right = test.Substring(test.Length - 10, 10));
It's not exactly much harder than using the RIGHT function, is it!

As to FileIO, .Net has a very rich set of features, and it's just a
case of learning the new syntax.

Rather than being 'something we should know', I think it should be seen
as 'something only to be used in an act of deperation, when all else
has failed, and you' can't be bothered to look for the correct
solution'! ;-)

I see you are an MCT - I hope you don't teach these techniques in your
classes!

Regards

Adam
 
M

Mark Rae

Rather than being 'something we should know', I think it should be seen
as 'something only to be used in an act of desperation, when all else
has failed, and you' can't be bothered to look for the correct
solution'! ;-)

Quite so! Is anyone still using On Error in VB.NET...?
I see you are an MCT - I hope you don't teach these techniques in your
classes!

Indeed!
 
G

Guest

Well, I teach those techniques to VB.NET developers who wanted to learn C# or
switching to C# but they prefere to use some VB style modules.
And it is not good to be in a class and someone ask "Oh, Can I use Strings
Module in C#?" And the answet would be No! if he did some research he will
find that I've give him an incorrect answer. Even if this technique in your
opinion is not good, or bad, or whatever, it has no bad performance I think
as well as many people likes it.
After all, these techniques is used in Some MOCs Workshops Labs in C# and
VB.NET so it is till I have to face this, and C# developers who don't know
VB.NET and they are many, would ask "What is this?! An is there any other
mean to do it in C#?". It is just a knowledge that is why I said we should
Know. Still those techniques are managed .Net class libraries.
Regards
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
 

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

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top