Make a program that associates all 26 English alphabets A-Z with the index 1-26. User

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dilawaiz
    New Member
    • Mar 2019
    • 1

    Make a program that associates all 26 English alphabets A-Z with the index 1-26. User

    Make a program that associates all 26 English alphabets A-Z with the index 1-26. User will enter a number from 1 to 26 and it will show the associated alphabet.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    well - never used c# but found a online fiddle to fiddle around with c# :) the basic idea could look like something like this:

    Code:
    using System;
    					
    public class Program
    {
    	public static void Main()
    	{	
    		char [] alpha = {'a', 'b', 'c', 'd'};
    		
    		string txt = Console.ReadLine();
    
    		Console.WriteLine(
    			alpha[Convert.ToInt32(txt)]
    		);
    	}
    }
    note that it needs adaption to your real case - and probably correct error handling and so forth. the idea is just to use an array with the elements you want to retrieve. now the input should be an integer between 0 and the array's length which then directly can be used to acces the corresponding element in the array.
    Last edited by gits; Mar 22 '19, 11:59 AM.

    Comment

    • SioSio
      Contributor
      • Dec 2019
      • 272

      #3
      In the following example,
      Enter a numerical value in textBox1 and press button1, the alphabet will be displayed in textbBx2.
      Code:
      		void Button1Click(object sender, EventArgs e)
      		{
      			textBox2.Text = Convert.ToChar(int.Parse(textBox1.Text) + 0x40) + "";
      		}

      Comment

      Working...