Java to C# Conversion "Console App"


Main Page


Assignment Description

In this assignment we were tasked to take a simple Java console Calculator application and rewrite it in C#. The main things to watch out for were; different naming conventions, declaration of variables, getters and setters, general syntax differences between the languages. I prepared for this assignment by taking time to read up on C# and looking for differences in the code. Also, I watched several videos on the differences between the languages in order to understand them better. Overall, C# is similar to Java, yet at the same time is a fuller and richer coding experience. C# coupled with Visual Studio 2017 is an excellent coding enviornment and language to develop in.

Link to: Homework Three


Getters and Setters

The example below shows a C# way of creating getters and setters for the variable Data. Compared to Java, where you must first initialize the variable, then create an entire get method, followed by a full set method. C# makes the process simple and less time consuming.

        public object Data
        {
               get { return data; }
               set { data = value; }
           
        }


Naming Conventions.

Interfaces just have one major difference in C# from java. The fact that they have a naming convention, when naming an interface, please name it appropriately and have it start with an "I" as seen below. Also, I should mention that the naming convention for String is now to initiate it as lower-case instead.

   public interface IStackADT


Commenting in C#

One of the C# features I enjoyed most was the /// comment. If you create a method, and finish the method. Adding a triple slash above it auto populates some great tags to help explain how your method works. As soon as it it populated all you need to do is fill in the parameter type, as well as a description of the method, and of course the return type if one exists.

        /// <summary>
        /// Pushes an item to the top of a stack.
        /// </summary>
        /// <param name="newItem">The item we  pusuh to the top.</param>
        /// <returns>returns a reference if no other item exists.</returns>


Conclusion

The core of C# is very similar to Java. If statements, loops, comments, and declarations are all similar with just a slightly different take on it. I completed the assignment by first setting up the project in Visual Studio. After that, I just went through class by class looking at how the Java code was implemented, then thinking about how that might change for C# and typing it in. If it didn't work, I tried again. Below this I have a link to the repository for this homework assignment.

Link To:Homework Three Repository







© Sam Wetzel 2017

swetzel13@wou.edu