Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Classes-and-Structures.cs
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) // Homework Assignment #3 /* Question 1 : What is the difference between a class and a structure? Answer 1 : Differences between class and structure are as follows: 1. Classes are of reference types while structures are of value types. 2. A Class can inherit from another class whereas a structure cannot. 3. A Class supports 'polymorphism' where as structure does not. 4. Data members in classes are by default private whereas data members in structures are by default public. 5. Class has limitless features whereas structures have limited features. 6. Class is generally used in large program whereas struct is generally used in small programs. */ /* Question 2 : When would you want to use one versus the other? Answer 2: When a user wants more freedom in terms of what he wants to do, class is the best option as it has limitless features whereas if the user wants a quicker and easier program without having to worry about polymorphism or inheritance structure is the best option. */ using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Monster { public string name_; public int size_; public int scare_; public int nMonsters_; //default consturctor -initiated all values public Monster() { name_="Test"; size_=20; scare_=10; nMonsters_++; //increment number of monsters } //Constructors public Monster( string name,int size,int scare) { name_=name; size_=size; scare_=scare; nMonsters_++; } // Methods public void print() { Console.WriteLine("Monster Name :" + name_); Console.WriteLine ("Monster Scare:" + scare_); Console.WriteLine("Monster Size:" + size_); } } public class Program { public static void Main(string[] args) { Monster Dinosaur = new Monster(); // Public Members Console.WriteLine(Dinosaur.name_); Monster Dragon = new Monster("Drako",30,24); Monster TRex = new Monster("Rex",45,41); Monster WereWolf = new Monster("Wolf",34,21); Console.WriteLine(Dragon.name_); Console.WriteLine(TRex.name_); Console.WriteLine(TRex.nMonsters_); WereWolf.print(); TRex.print(); Dragon.print(); } } }
run
|
edit
|
history
|
help
0
الحاسوب
IEquatable_Object compare
Test
Only certain spheres.
3
name generator
edmond@DESKTOP-M2BC2LH
gass
ch.murali krishna
Trim Strings