Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

With Char for loop

My question; I want two different char value from user. For example BlockStart=a and BlockFinish=d
after then I want doing for loop ‘d’ to ‘a’
I did BlockStart and BlockFinish properties char type and
I prepared for loop:
{ for (char i = dto.BlockStartAlphabetical; i <= dto.BlockFinishalphabetical; i++) {} }

but this expression don’t come in for loop.
What can I do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Well you can use linq in a way that helps you to build an array of characters like below :

var start = 'a';
var end = 'd';
var result = Enumerable.Range(0,end-start+1).Select(ix=> (char)(start+ix)).ToArray();

// result = [a,b,c,d]

Fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading