Beginning Visual C# Exercises - Chapter 21 Answers
1. Modified AssemblyInfo.cs (inspired by a song)....
[assembly: AssemblyTitle("Listen to Yardbirds Class Library")]
[assembly: AssemblyDescription("Classes of Things To Come")]
[assembly: AssemblyConfiguration("Beginner Lesson Version")]
[assembly: AssemblyCompany("Yardbirds Said It All, Ltd")]
[assembly: AssemblyProduct("Shapes")]
[assembly: AssemblyCopyright("Copyright 2004, Yardbirds Said It All, Ltd")]
[assembly: AssemblyTrademark("Shapes is a trademark of Yardbirds Said It All, Ltd")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.3.*")]
Build and then view via Ildasm....
2. Write a square class in MoreShapes with the circle and triangle...
using System;
using System.Drawing;
namespace MoreShapes
{
public class Square
{
double Side;
public Square() : this(0d)
{
}
public Square(double givenSide)
{
Side = givenSide;
}
public double Area()
{
// area = Side squared
return Side * Side;
}
}
public class Circle
{
double Radius;
public Circle() : this(0d)
{
}
public Circle(double givenRadius)
{
Radius = givenRadius;
}
public double Area()
{
// area = pi r squared
return Math.PI * (Radius * Radius);
}
public void Draw()
{
Pen p = new Pen(Color.Red);
}
}
public class Triangle
{
double Base;
double Height;
public Triangle() : this(0d, 0d)
{
}
public Triangle(double givenBase, double givenHeight)
{
Base = givenBase;
Height = givenHeight;
}
public double Area()
{
// area = 1/2 base * Height
return 0.5F * Base * Height;
}
}
}
Build and then view via Ildasm....
3. ShapeUser refers to MoreShapes assembly...
using System;
<s>//using Shapes;</s>
using MoreShapes;
namespace ShapeUser
{
public class ShapeUser
{
public static void Main()
{
double radius = 2.0;
Circle c = new Circle(radius);
Console.WriteLine("Area of Circle (2.0) is {0:f}", c.Area());
Console.ReadLine();
}
}
}
Build and then view via Ildasm....
4. I just added code to the ShapeUser Class....
public static void Main()
{
double radius = 2.0;
Circle c = new Circle(radius);
Console.WriteLine("Area of Circle (2.0) is {0:f}", c.Area());
double side = 2.5;
Square sq = new Square(side);
Console.WriteLine("Area of Square (2.5) is {0:f}", sq.Area());
double bottom = 3.0;
double height = 1.5;
Triangle tr = new Triangle(bottom, height);
Console.WriteLine("Area of Triangle (3.0, 1.5) is {0:f}", tr.Area());
Console.ReadLine();
}
Build and then view via Ildasm....
5. There is a lot of info to display so use the "more" pipe....
gacutil /l | more
- OR -
gacutil /lr | more
6. Strong Name - nothing to show here - learn by doing....
7. Global Assembly Cache - nothing to show here - learn by doing....
|