Programming process

Programming process

  1. Identify what you are trying to do.
    • Ex: are you trying to convert pounds to ounces, are you trying to reverse a string, are you trying make a object move back and forth on the screen, etc
  2. Figure out how to do that or plan the solution
    • In my experience you do this in a flow chart, puesdo code or both, although depending on how simple what your trying to do is it might not be necessary
    • For more complex programs its helpful with making sure you plan for all the different cases in which your program may be used
  3. Code the program and decide the language you are using
    • This may include looking up ways to do what you planned in the previous step in the language you choose.
  4. Test and debug your code
    • In this step you are basically making sure it works in a variety of cases, if your practicing on a website, they do the testing part for you.
    • If your not on a website practicing this involves coming up with test cases and figuring out how to see if it is correct.
  5. Documenting
    • For me this normally involves commenting what things are suppose to do , but normally for me its a program for personal use.
    • If its for a company or something it would probably include, the origin of the problem, a description of the program, the psuedo code and/or flow chart, data-record descriptions, a list of all the programs involved, testing results , and commenting on what stuff is suppose to do.
    • This step should really be done throughout the creation of the program.

A example of this process is in this video which will done using CodeWars, cause I didn’t want to come up with a problem, or tests, I also will only be commenting for documentation.

C# Arrays- useful methods(no examples)

C# Arrays- useful methods(no examples)

Properties

So properties are used like : arrayName.propertyName

The Rank property will tell you how many dimensions the array has.

The Length property will tell you how many elements are in a array.

Methods

The copy() method creates a copy of the array. The copy is shallow this means that it copies all the elements of the array whether its a reference type or a value type. However, it doesn’t create copies of objects it just copies the reference to that object. (a deep copy would create a copy of that object so the original and the copy would not be referencing the same object)

The Clear(Array array , int index, int length) method will turn the array starting from the index for length elements. So if you put 2 for index and 5 for length, it will set from index 2 to index 6 to the default for their type.

The GetLength(int dimension) method will return the length of the dimension you gave it. So say you are using a three dimensional array and you put a 2 for the parameter, it will give you the length of the third dimension. (it counts dimensions starting from 0 so for a single dimension array you would only be able to find the length of the 0 dimension without a error)

The GetType() method will return the type of a object it is, so if its a int it will return int if its a long it will return long, if the array is of a class you made it will return that classes name.( to clarify the full method is Object.GetType() not Array.GetType(), although a array is technically a object)

The GetValue(…) method has eight different version. Although there are really only 4 kinds, they just specify the indexes of 32 bit integer (Int32 or int) or 64 bit integer (Int64 or long). So I’ll be using int but each instance of the method could have long as the type for all the parameters.(Note: all parameters must be int or long you cant mix and match them within the same method). Also keep in mind that indexes start from zero in a array.

  1. So GetValue( int index1) is for use with single dimension arrays and will give you the value of the element at that index.
  2. GetValue( int index1 , int index2) is for two-dimensional arrays, and will give you the value of a array at index1 in the first dimension and index2 in the second dimension.
  3. GetValue( int index1, int index2, int index3) is for three dimensional arrays.
  4. GetValue(int[] indices) is for multi-dimensioanl arrays, the number of elements in indices should be equal to the number of dimensional the array you are trying to get a value from with element 0 being the index in the first dimension. (I am assuming)

The SetValue( Object value . . ) method basically the same as GetValue but you are setting the values at those indices, so you also need the value parameter which will be the first one.

The IndexOf( . . .) method has 6 different versions. I will be covering three because the other three just seem to be slightly different versions of these three. Also this only works for one dimensional arrays.

  1. IndexOf(Array array, object value) will return the first index that value appears in the array as a int. Everything is a object so don’t worry about the type.
  2. IndexOf (Array array, object value, int startIndex) will return the first index of the value starting from startIndex in the array as a int.
  3. IndexOf (Array array, object value, int startIndex, int count) will return the first index of the value from between startIndex and startIndex+count-1. So if start index is 2 and count is 5 it will be from between indices of 2 and 6.

The LastIndexOf( . . .) method is the same as IndexOf but its just the last index that the value appears at rather than the first.

The Sort( . . . ) method has 17 different version 9 look very similar to the other 8. Of which I will only be going over two because all the others involve a IComparer parameter which I believe is just something telling the method specifically how you want it sorted or it wants you to use another array as a key for the one your sorting.

  1. Sort (Array array, int index, int length) will rearrange the elements from index for length. So say index is 2 length is five the elements from 2 to 6 will be rearranged according to the default, which I believe would be something like alphabetical for strings.(so like if the array was the alphabet the first element would be “A”.
  2. Sort(Array array) will rearrange the entire array according to the default IComparer.