CS3505/5020 Software Practice II
C# Vector Review Homework Help
CS 3505 L03 - 1
CS3505/5020 Software Practice II C# Vector Review Homework Help - - PowerPoint PPT Presentation
CS3505/5020 Software Practice II C# Vector Review Homework Help CS 3505 L03 - 1 Decimal primitive Use lowercase m to denote decimal numbers Stored internally as integers with a base 10 decimal point. Ideal for money or
CS 3505 L03 - 1
Decimal x, y; x = 4.5m; y = 4.500m; Console.WriteLine(x); // Outputs 4.5 Console.WriteLine(y); // Outputs 4.500 y = Decimal.Round(y, 2); Console.WriteLine(y); // Outputs 4.50
CS 3505 L03 - 3
CS 3505 L02 - 4
CS 3505 L02 - 5
CS 3505 L02 - 6
CS 3505 L02 - 7
These are properties which we’ll describe later.
CS 3505 L02 - 8
CS 3505 L02 - 9
CS 3505 L02 - 10
Java – All by value -- Primitives by value, objects by value of reference C++ – By value with copy constructors for objects, reference by specification C# – Primitives by value; Objects by ref; Value can be by ref by saying “ref” – “out” – just like “ref” except initial value ignored, and MUST be assigned using System; public class RefClass { public static void Main(string[] args) { int total = 20; Console.WriteLine("Original value of 'total': {0}", total); // Call the Add method Add (10, ref total); Console.WriteLine("Value after Add() call: {0}", total); } public static void Add (int i, ref int result) { result += i; } }
CS 3505 L02 - 11
Formalized getter/setter model of Java
Compiles to get_Species/set_Species for languages that
CS 3505 L02 - 12
Does not HAVE to be an int, but
you want.
CS 3505 L02 - 13
CS 3505 L02 - 14
C# Compiler forces increasing generality when using multiple exceptions
CS 3505 L02 - 15
Will actually call both the Add AND the Multiply methods
CS 3505 L02 - 16
CS 3505 L02 - 17
CS 3505 L02 - 18
CS 3505 L02 - 19
CS 3505 L02 - 20
CS 3505 L02 - 21
CS 3505 L02 - 22
CS 3505 L02 - 23
using System; using System.Threading; class Test { static void printA () { while (true) { Console.Write("A");} } static void printB () { while (true) { Console.Write("B");} } public static void Main () { Thread a = new Thread(new ThreadStart(printA)); Thread b = new Thread(new ThreadStart(printB)); a.Start(); b.Start(); } }
AABBBBAAAABBBBBBAAAAAABBBABA BBBAABABBBABBAAAABABABABABBB ABBBABBBABBBBBBBABBABBBBBAAA AAAABBBABBABBBABBBBABABABBBA BABABBABABBBAABAAABABBBABBBB
CS 3505 L02 - 24
CS 3505 L02 - 25
CS 3505 L02 - 26
<sum m ar y>, <r em ar ks> Type or member <par am > Method parameter <r et ur ns> Method return value <except i on> Exceptions thrown from method <exam pl e>, <c>, <code> Sample code <see>, <seeal so> Cross references <val ue> Property <par am r ef > Use of a parameter <l i st >, <i t em >, . . . Formatting hints <per m i ssi on> Permission requirements
CS 3505 L02 - 27
CS 3505 L02 - 28
CS 3505 L02 - 29
CS 3505 L02 - 30
CS 3505 L02 - 31
CS 3505 L02 - 32
Lots of performance studies One that seems competent is (but this is a couple years old):
– http://www.tommti-systems.de/go.html?http://www.tommti- systems.de/main-Dateien/reviews/languages/benchmarks.html
Some numbers:
– Maximum memory usage: – Java - 163 MB – C# - 111 MB – Cpp - 98 MB
Performance summary (lots of tests)
– Cpp is the fastest, except the STL "hashmaps" (11 wins against C#) – C# is quit fast (problems with exception handling, matrix multiply and nested loops) – Java is slower, but hash maps are very fast and the exception handling is also very strong. – C++ 11 wins against C# – Java 5 wins against C# – C# 9 wins against Java – C# 2 wins against C++
CS 3505 L02 - 33
C# has lots of nice features Clearly C# was built after C++ and Java and fixes problems
C# language feels more like C++ C# environment is more Java like Easy to learn language Your work will be in learning the libraries (.Net Framework and
More advanced C# includes:
CS 3505 L02 - 34
(12, 5) (16, 2)
(12, 5) (19, 6)
CS 3505 L02 - 41