count number of characters in an int c# code example

Example 1: how to count letters in c#

int numberOfLetters = yourWord.Length;

Example 2: count number of characters in an int c#

/// You can do this two ways.
/// First way (below)
public int getcharsforeach(int l) {
  	int charnum = 0;
	foreach (char c in l.ToString()) {
    	charnum += 1;
    }
  	return charnum;
}
/// Second way (below)
public int getcharlength(int l) {
	int letters = l.ToString().Length;
  	return letters;
}

Example 3: count number of characters in an int c#

/// You can do this two ways.
/// First way (below)
public int getcharsforeach(int l) {
  	int charnum = 0;
	foreach (char c in l.ToString()) {
    	charnum += 1;
    }
  	return charnum;
}
/// Second way (below)
public int getcharlength(int l) {
	int letters = l.ToString().Length;
  	return letters;
}

Tags:

Misc Example