{"id":4734,"date":"2016-12-06T04:00:12","date_gmt":"2016-12-06T04:00:12","guid":{"rendered":"https:\/\/assignment.essayshark.com\/blog\/?p=4734"},"modified":"2022-01-12T10:30:57","modified_gmt":"2022-01-12T10:30:57","slug":"c-programming-code-examples-finding-a-palindrome","status":"publish","type":"post","link":"https:\/\/assignmentshark.com\/blog\/c-programming-code-examples-finding-a-palindrome\/","title":{"rendered":"C# Programming Code Examples: Finding a Palindrome"},"content":{"rendered":"<p>In this guide I will show you how to create a program on Windows Forms which will help us to determine if the symbols that we input constitute a palindrome.<\/p>\n<p>Let\u2019s create a simple user interface:<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4736 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-1.png\" alt=\"finding-a-palindrome-using-c-1\" width=\"380\" height=\"144\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-1.png 380w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-1-300x114.png 300w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><\/a><\/p>\n<p>Here we have a TextBox, Label, and Button. The message with the result of checking will be shown using MessageBox.<\/p>\n<p>Double click the button \u201cCheck it\u201d and go to the part of the code where we will perform the checking.<!--more--><\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nstring stext = textBox1.Text;<br \/>\nchar[] ctext = stext.ToCharArray();<br \/>\n[\/code]<\/p>\n<p>First, we create the string for user\u2019s input and write it to the \u201cstext\u201d variable. Then we create the char array to read the string symbol by symbol. Then we will be able to turn around our text.<\/p>\n<p>Convert the text from string format to char using .ToCharArray method.<br \/>\nTurn around the text using:<\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nArray.Reverse(ctext);<br \/>\n[\/code]<\/p>\n<p>Now we have a char array with reversed symbols. But we should compare strings, so we should convert it to string:<\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nstring resulttext = new string(ctext);<br \/>\n[\/code]<\/p>\n<p>So now we should just compare the inputted string with the one we turned around:<\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\n    if(stext == resulttext)<br \/>\n    {<br \/>\n    MessageBox.Show(&quot;This expression is a palindrome&quot;);<br \/>\n    }<br \/>\n    if (stext != resulttext)<br \/>\n    {<br \/>\n    MessageBox.Show(&quot;This expression is not a palindrome&quot;);<br \/>\n    }<br \/>\n[\/code]<\/p>\n<p>The program is ready to use!<\/p>\n<p>Screenshots:<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4742 aligncenter\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-2.png\" alt=\"finding-a-palindrome-using-c-2\" width=\"600\" height=\"147\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-2.png 628w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-2-300x74.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4746 aligncenter\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-3.png\" alt=\"finding-a-palindrome-using-c-3\" width=\"600\" height=\"150\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-3.png 605w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-3-300x75.png 300w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/10\/Finding-a-palindrome-using-C-3-604x151.png 604w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Code listing:<\/p>\n<p><strong>Form1.cs:<\/strong><\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\n    using System;<br \/>\nusing System.Collections.Generic;<br \/>\nusing System.ComponentModel;<br \/>\nusing System.Data;<br \/>\nusing System.Drawing;<br \/>\nusing System.Linq;<br \/>\nusing System.Text;<br \/>\nusing System.Threading.Tasks;<br \/>\nusing System.Windows.Forms;<\/p>\n<p>namespace palindrom_wf<br \/>\n{<br \/>\n    public partial class Form1 : Form<br \/>\n    {<br \/>\n        public Form1()<br \/>\n        {<br \/>\n            InitializeComponent();<br \/>\n        }<\/p>\n<p>        private void button1_Click(object sender, EventArgs e)<br \/>\n        {<br \/>\n            string stext = textBox1.Text;<br \/>\n            char[] ctext = stext.ToCharArray();<br \/>\n            Array.Reverse(ctext);<br \/>\n            string resulttext = new string(ctext);<br \/>\n            if(stext == resulttext)<br \/>\n            {<br \/>\n                MessageBox.Show(&quot;This expression is a palindrome&quot;);<br \/>\n            }<br \/>\n            if (stext != resulttext)<br \/>\n            {<br \/>\n                MessageBox.Show(&quot;This expression is not a palindrome&quot;);<br \/>\n            }<\/p>\n<p>        }<br \/>\n    }<br \/>\n}<br \/>\n[\/code]<\/p>\n<p><strong>Form1.Designer.cs:<\/strong><\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\nnamespace palindrom_wf<br \/>\n{<br \/>\n    partial class Form1<br \/>\n    {<\/p>\n<p>        private System.ComponentModel.IContainer components = null;<\/p>\n<p>        protected override void Dispose(bool disposing)<br \/>\n        {<br \/>\n            if (disposing &amp;&amp; (components != null))<br \/>\n            {<br \/>\n                components.Dispose();<br \/>\n            }<br \/>\n            base.Dispose(disposing);<br \/>\n        }<\/p>\n<p>        private void InitializeComponent()<br \/>\n        {<br \/>\n            this.textBox1 = new System.Windows.Forms.TextBox();<br \/>\n            this.label1 = new System.Windows.Forms.Label();<br \/>\n            this.button1 = new System.Windows.Forms.Button();<br \/>\n            this.SuspendLayout();<br \/>\n            \/\/<br \/>\n            \/\/ textBox1<br \/>\n            \/\/<br \/>\n            this.textBox1.Location = new System.Drawing.Point(134, 13);<br \/>\n            this.textBox1.Name = &quot;textBox1&quot;;<br \/>\n            this.textBox1.Size = new System.Drawing.Size(229, 20);<br \/>\n            this.textBox1.TabIndex = 0;<br \/>\n            \/\/<br \/>\n            \/\/ label1<br \/>\n            \/\/<br \/>\n            this.label1.AutoSize = true;<br \/>\n            this.label1.Location = new System.Drawing.Point(12, 16);<br \/>\n            this.label1.Name = &quot;label1&quot;;<br \/>\n            this.label1.Size = new System.Drawing.Size(83, 13);<br \/>\n            this.label1.TabIndex = 1;<br \/>\n            this.label1.Text = &quot;Input the expression&quot;;<br \/>\n            \/\/<br \/>\n            \/\/ button1<br \/>\n            \/\/<br \/>\n            this.button1.Location = new System.Drawing.Point(20, 50);<br \/>\n            this.button1.Name = &quot;button1&quot;;<br \/>\n            this.button1.Size = new System.Drawing.Size(343, 43);<br \/>\n            this.button1.TabIndex = 2;<br \/>\n            this.button1.Text = &quot;Check it!&quot;;<br \/>\n            this.button1.UseVisualStyleBackColor = true;<br \/>\n            this.button1.Click += new System.EventHandler(this.button1_Click);<br \/>\n            \/\/<br \/>\n            \/\/ Form1<br \/>\n            \/\/<br \/>\n            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br \/>\n            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br \/>\n            this.ClientSize = new System.Drawing.Size(374, 108);<br \/>\n            this.Controls.Add(this.button1);<br \/>\n            this.Controls.Add(this.label1);<br \/>\n            this.Controls.Add(this.textBox1);<br \/>\n            this.Name = &quot;Form1&quot;;<br \/>\n            this.Text = &quot;Palindrome check&quot;;<br \/>\n            this.ResumeLayout(false);<br \/>\n            this.PerformLayout();<\/p>\n<p>        }<\/p>\n<p>        private System.Windows.Forms.TextBox textBox1;<br \/>\n        private System.Windows.Forms.Label label1;<br \/>\n        private System.Windows.Forms.Button button1;<br \/>\n    }<br \/>\n}<br \/>\n[\/code]<\/p>\n<blockquote><p><em>Did you like one of our C# programming code examples? It was completed by a well-qualified expert in C# programming. If you need to get <a href=\"https:\/\/assignmentshark.com\/\" target=\"_blank\" rel=\"noopener\">assignment help<\/a> with C# feel free to contact AssignmentShark. Our experts are capable of completing any <a href=\"https:\/\/assignmentshark.com\/blog\/assignment-examples-the-one-about-duck-typing-in-c\/\" target=\"_blank\" rel=\"noopener noreferrer\">assignment examples<\/a> and technical tasks. Just specify your requirements in detail and get timely help. When you use our service there\u2019s no need to worry about your confidentiality. All your personal and financial information is kept in secret. Also you should know that you pay via independent payment system and you release payments after you get the order. Are you eager to work with us? Do not hesitate! Order assignment of the same quality as our C# programming code examples and increase your chances to get high scores!<\/em><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>In this guide I will show you how to create a program on Windows Forms which will help us to determine if the symbols that we input constitute a palindrome. Let\u2019s create a simple user interface: Here we have a TextBox, Label, and Button. The message with the result of checking will be shown using [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53,35],"tags":[],"class_list":["post-4734","post","type-post","status-publish","format-standard","hentry","category-it","category-samples"],"_links":{"self":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/4734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/comments?post=4734"}],"version-history":[{"count":13,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/4734\/revisions"}],"predecessor-version":[{"id":13017,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/4734\/revisions\/13017"}],"wp:attachment":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/media?parent=4734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/categories?post=4734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/tags?post=4734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}