Thursday, January 12, 2012

Thursday 1-12-12

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
Photo *photo1 = [[Photo alloc] init];
NSLog(@"photo1 caption: %@", photo1.caption);
NSLog(@"photo1 photographer: %@", photo1.photographer);

photo1.caption = @"Overlooking the Golden Gate Bridge";
photo1.photographer = @"(Your name here)";

NSLog(@"photo1 caption: %@", photo1.caption);
NSLog(@"photo1 photographer: %@", photo1.photographer);

[photo1 release];

Photo* photo2 = [Photo photo];

NSLog(@"photo2 caption: %@", photo2.caption);
NSLog(@"photo2 photographer: %@", photo2.photographer);

photo2.caption = @"Moffett Field";
photo2.photographer = @"(Your Name Here)";

NSLog(@"photo2 caption: %@", photo2.caption);
NSLog(@"photo2 photographer: %@", photo2.photographer);
}



#import

@interface Photo : NSObject
{
NSString *caption;
NSString *photographer;
}

+(Photo*) photo;

- (NSString*) caption;
- (NSString*) photographer;

- (void) setCaption: (NSString*)input;
- (void) setPhotographer: (NSString*)input;
@end




#import "Photo.h"

@implementation Photo
-(id) init {
if (self = [super init]){
[self setCaption:@"Default Caption"];
[self setPhotographer:@"Default Photographer"];
}
return self;
}

+ (Photo*) photo{
Photo* newPhoto = [[Photo alloc] init];
return [newPhoto autorelease];
}

-(NSString*) caption {
return caption;
}

-(NSString*) photographer {
return photographer;
}

- (void) setCaption: (NSString*) input {
[caption autorelease];
caption = [input retain];
}

-(void) setPhotographer: (NSString*)input {
[photographer autorelease];
photographer = [input retain];
}

- (void) dealloc {
[self setCaption:nil];
[self setPhotographer:nil];

[super dealloc];
}

@end




namespace NewBase
{


class Base
{
public virtual void DoSomethingVirtual()
{
Console.WriteLine("Base.DoSomethingVirtual");
}

public void DoSomethingNonVirtual()
{
Console.WriteLine("Base.DoSomethingNonVirtual");
}
}

class Derived : Base
{
public override void DoSomethingVirtual()
{
Console.WriteLine("Derived.DoSomethingVirtual");
}

public new void DoSomethingNonVirtual()
{
Console.WriteLine("Derived.DoSomethingNonVirtual");
}
}

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Derived via Base reference:");

Base baseRef = new Derived();
baseRef.DoSomethingVirtual();
baseRef.DoSomethingNonVirtual();

Console.WriteLine();
Console.WriteLine("Derived via Derived reference:");

Derived derivedRef = new Derived();
derivedRef.DoSomethingVirtual();
derivedRef.DoSomethingNonVirtual();
}
}
}


namespace CA2
{
public struct Point
{
private Int32 _x;
private Int32 _y;

public Int32 X
{
get { return _x; }
set { _x = value; }
}

public Int32 Y
{
get { return _y; }
set { _y = value; }
}

public Point(int x, int y)
{
_x = x;
_y = y;
}


}

class Program
{
static void Main(string[] args)
{


Point p2 = new Point();
p2.X = 15;
p2.Y = 23;
Console.WriteLine("{0} / {1}", p2.X, p2.Y);
}
}
}

No comments:

Post a Comment