I.T. Discussion Community!
-Collapse +Expand
C#
Search C# Group:

Advanced
-Collapse +Expand C# To/From
To/FromCODEGuides
-Collapse +Expand C# Study Test
PRESTWOODCERTIFIED
-Collapse +Expand C# Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyC# (Visual C# & VS.Net) BoardC# & WinForms Topic   Print This     

abstract keyword

abstract keyword in C# & WinForms topic (part of our C# (Visual C# & VS.Net) group).

Quick Search: abstract   keyword   abstract keyword  
cheddar
Lodi, CA
do methods defined with the abstract keyword have to be defined inside of an abstract class? I am converting some vb.net code and the MustOverride keyword doesn't appear to directly translate.

TIA
Eric Neff
C#, ASP.Net, SQL Server, Oracle
 Posted 15 years ago (Thread Starter)
Comment Quote
About cheddar -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #10273, 2 replies
Thread Started 1/22/2004 7:15:00 PM
View Counter=3953
Last Reply Posted 2/3/2004 7:19:00 AM)
Location=Lodi, CA  
Joined=18 years ago   MB Posts=88  
Most Recent Post
cheddar
Lodi, CA
Thx for the answer sandman. What I was trying to figure out was abstract methods in non-abstract classes. I am backing up and going through a c# patterns book. I hope the controller pattern holds the solution.

BTW, where in No Cal are you?
Eric Neff
C#, ASP.Net, SQL Server, Oracle
 Posted 15 years ago (Thread Starter)
Comment Quote
About cheddar -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #10308 (Level 1.1)  Reply to 10273
Thread Started 2/3/2004 7:19:00 AM
View Counter=2
Location=Lodi, CA  
Joined=18 years ago   MB Posts=88  
Sandman
 (Inactive)
Northern Ca.
I was going through a old manual and found this on abstract keywords.
Don't know if it will be any help to you or not ?

abstract

The abstract modifier is used in classes, methods and properties.
Abstract modifier is used when you want the class to be a base class for other classes.
Key points concerning abstract classes:
May not be instantiated.
May contain abstract methods and accessors.
Cannot be modified with the sealed modifier.
A non-abstract class derived from an abstract class must include actual implementations of all the inherited abstract methods and accessors
You may use the abstract modifier in methods and properties to serve the same purpose of not having implementations of it.
Key points concerning Abstract methods:
It is implicitly a virtual method.
May only be declared in abstract classes.
There is no method body since there is no implementation of it during declaration. E.g.

public abstract void GetUserInfo(); // no {} after the signature


The actual implementation is provided by an overriding method which is of course of a non-abstract class.
The following modifiers are not allowed in an abstract method declaration: static, virtual and override.
Abstract properties are similar to abstract methods except for declaration and invocation syntax. Key points concerning abstract properties:
May not be static
An abstract inherited property can be overridden in a derived class by including a property declaration that uses the override method.
An abstract class has to provide implementations for all of its interface members.
Sample:

// Abstract classes
using System;

abstract class MyAbstractC // Abstract class
{
protected int iHours = 40;
protected int iWage = 25; // A VB developer? *smirk*

// Abstract method
public abstract void DoOvertime();

// Abstract property
public abstract int GetHours
{
get;
}

// Abstract property
public abstract int GetWage
{
get;
}
}

// Derived from abstract class, MyAbstractC
class MyDerivedC: MyAbstractC
{
// overriding the method
public override void DoOvertime()
{
iHours = 50;
iWage = 38;
}

// overriding the property
public override int GetHours
{
get
{
return iHours;
}
}

// overriding the property
public override int GetWage
{
get
{
return iWage;
}
}

public static void Main()
{
// instance of derived class
MyDerivedC dC = new MyDerivedC();

dC.DoOvertime();
Console.WriteLine("Hours worked = {0},
Wage earned = {1}", dC.GetHours, dC.GetWage);

// Pause output window
Console.ReadLine();

}

}


Output: Hours worked = 50, Wage earned = 38

Confused
 Posted 15 years ago
Comment Quote
About Sandman -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #10306 (Level 1.2)  Reply to 10273
Reply Posted 2/3/2004 1:56:00 AM
Location=Northern Ca.  
Joined=17 years ago   MB Posts=23  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1173A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #10273 Counter
3953
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech