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
   ► KBProgrammingC#OOP   Print This     

C# KB: OOP Topic



20 Articles Found in the OOP Topic 

  KB Article    

Mike Prestwood
1. C# Abstraction (abstract, override)

C# supports abstract class members and abstract classes using the abstract modifier. An abstract class is a class with one or more abstract members and you cannot instantiate an abstract class. However, you can have additional implemented methods and properties. An abstract member is either a method (implicitly virtual), property, indexer, or event in an abstract class. You can add abstract members ONLY to abstract classes using the abstract keyword.

12 years ago, and updated 11 years ago

Code

Article
Nothing New Since Your Last Visit  
34046
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
2. C# Access Modifiers

In C#, you specify each class and each class member's visibility with an access modifier. The C# access modifiers are the traditional public, protected, and private plus the two additional .Net modifiers internal and protected internal.

Internal indicates members are accessible from types in the same assembly. Protected internal indicates members are accessible from types in the same assembly as well as descendant classes. OO purist might object to internal and protected internal and I suggest you choose private, protected, or public over them until you both fully understand them and have a need that is best suited by them.

The default for class and class members is Internal (members are accessible from types in the same assembly). This is different than with interfaces where the default for an interface is Internal but an interface's members are always public -- which makes sense but is noteworthy.

With both classes and interfaces, if you make a class public, the members are public. This applies to the other access modifiers too. For example, if you make a class protected, the members default access modifiers are protected.

12 years ago, and updated 11 years ago

Code
Nothing New Since Your Last Visit  
10061
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
3. C# Base Class (System.Object)

In C#, the Object keyword is an alias for the base System.Object class and is the single base class all classes ultimately inherit from.

12 years ago, and updated 11 years ago

Code
Nothing New Since Your Last Visit  
8438
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
4. C# Class..Object (class...new)

In C#, you use the class keyword to specify a class and you signify its parent with a colon and the name of the parent class. When you instantiate an object from a class, you use the new keyword.

12 years ago, and updated 11 years ago

Code

KB Post
Nothing New Since Your Last Visit  
12881
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
5. C# Constructors (Use class name)

In C#, a constructor is called whenever a class or struct is created. A constructor is a method with the same name as the class with no return value and you can overload the constructor. If you do not create a constructor, C# will create an implicit constructor that initializes all member fields to their default values.

Constructors can execute at two different times. Static constructors are executed by the CLR before any objects are instantiated. Regular constructors are executed when you create an object.

11 years ago, and updated 11 years ago

Code

Article
Nothing New Since Your Last Visit  
17058
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
6. C# Finalizer (~ClassName)

Use a destructor to free unmanaged resources. A destructor is a method with the same name as the class but preceded with a tilde (as in ~ClassName). The destructor implicity creates an Object.Finalize method (you cannot directly call nor override the Object.Finalize method).

In C# you cannot explicitly destroy an object. Instead, the .Net Frameworks garbage collector (GC) takes care of destroying all objects. The GC destroys the objects only when necessary. Some situations of necessity are when memory is exhausted or you explicitly call the System.GC.Collect method. In general, you never need to call  System.GC.Collect.

11 years ago

Code

Article
Nothing New Since Your Last Visit  
16084
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
7. C# Inheritance-Multiple (Not Supported)

C# does not support multiple implementation inheritance. Each class can have only one parent class (a single inheritance path). In C#, you can use multiple interface usage to design in a multiple class way horizontally in a class hierarchy.

12 years ago, and updated 11 years ago

Code
Nothing New Since Your Last Visit
6010
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
8. C# Interfaces (interface)

Classes and structs can inherit from interfaces in a manner similar to how classes can inherit a base class or struct, but a class or struct can inherit more than one interface and it inherits only the method names and signatures, because the interface itself contains no implementations.

class MyClass: IMyInterface
{
  public object Clone()
{
return null;
}

// IMyInterface implemented here...
}
12 years ago, and updated 11 years ago

Code

Article
Nothing New Since Your Last Visit
15431
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
9. C# Member Field

In C# you can set the visibility of a member field to any visibility: private, protected, public, internal or protected internal.

You can intialize a member field with a default when declared. If you set the member field value in your constructor, it will override the default value.

Finally, you can use the static modifier (no instance required) and readonly modifier (similar to a constant).

11 years ago, and updated 11 years ago

Code
Nothing New Since Your Last Visit  
8796
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
10. C# Member Method

In C# you can set the visibility of a member field to any visibility: private, protected, public, internal or protected internal. You can intialize a member field with a default when declared. If you set the member field value in your constructor, it will override the default value. Finally, you can use the static modifier (no instance required) and readonly modifier (similar to a constant).

12 years ago, and updated 11 years ago
(1 Comments , last by KalaP.Bros.K )

Code

Article
Nothing New Since Your Last Visit
13559
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
11. C# Member Modifiers

The method modifiers are abstract, extern, new, partial, sealed, virtual, and override. Specify C# member modifiers as follows:

abstract SomeMethod() {..}

The field modifiers are const, readonly, static, volatile. Specify field modifiers as follows:

readonly int MyAge;

11 years ago

Code
Nothing New Since Your Last Visit
7907
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
12. C# Member Property (no (), get, set)

In C#, parens indicate a method and the lack of parens indicate a property. You use special get and set methods to both get and set the values of properties. For a read-only property, leave out the set method. The value keyword is used to refer to the member field. Properties can make use of any of the access modifiers (private, protected, etc). It is common to use a lowercase member names for member fields ("name" in our example) and uppercase properties to manage member fields ("Name" in our example).

12 years ago, and updated 11 years ago

Code

Article
Nothing New Since Your Last Visit  
16583
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
13. C# Overriding (virtual, override)

Method overriding allows you to define or implement a virtual method in a parent class and then replace it in a descendant class. In C#, you specify a virtual method with the virtual keyword in a parent class and replace it in a descendant class using the override keyword.

12 years ago, and updated 11 years ago
(4 Comments , last by Faith.A )

Code

Article
Nothing New Since Your Last Visit
26495
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
14. C# Partial Classes (partial)

C# uses the keyword partial to specify a partial class. All parts must be in the same namespace.

A partial class, or partial type, is a class that can be split into two or more source code files and/or two or more locations within the same source file. Each partial class is known as a class part or just a part. Logically, partial classes do not make any difference to the compiler. The compiler puts the class together at compile time and treats the final class or type as a single entity exactly the same as if all the source code was in a single location.

You can use them for many things including to separate code generator code, organize large classes, divice a class up so you can split ownwership among multiple developers, have different versions of the same class, and to utilize multiple languages with a single class.

11 years ago, and updated 11 years ago
(1 Comments , last by Assignment.H )

Code

Article
Nothing New Since Your Last Visit  
27592
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
15. C# Polymorphism

C# supports the following types of polymorphism:

12 years ago, and updated 11 years ago

Code
Nothing New Since Your Last Visit
8309
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
16. C# Prevent Derivation (sealed)

With C#, use the sealed keyword to prevent a class from being inherited from and to prevent a method from being overridden.

A method marked sealed must override an ancestor method. If you mark a class sealed, all members are implicitly not overridable so the sealed keyword on members is not legal.

12 years ago, and updated 11 years ago

Code
Nothing New Since Your Last Visit
7159
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
17. C# Self Keyword (this)

To refer to the current instance of a class, use the this keyword. The this keyword provides a way to refer to the specific instance in which the code is currently executing. It is particularly useful for passing information about the currently executing instance.

The this keyword is also used as a modifier of the first parameter of an extension method.

You cannot use this with static method functions because static methods do not belong to an object instance. If you try, you'll get an error.

11 years ago
(4 Comments , last by Mike.B3 )

Code
Nothing New Since Your Last Visit
24401
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
18. C# Static Members (static)

C# supports both static members and static classes using the static keyword. You can add a static method, field, property, or event to an existing class. Also, you can designate a class as static and the compiler will ensure all members in that class are static. You can add a constructor to a static class to initialize values.

The CLR automatically loads static classes with the program or namespace.

12 years ago, and updated 11 years ago

Code
Nothing New Since Your Last Visit
9091
Hits

C# (Visual C# & VS.Net)

khemebuen
19. Extension Methods in C#

Add new methods to predefined types and objects with extension methods (no need to recompile the base code).  To use this extension, all i have to do is include the  namespace ExtensionExample.

11 years ago, and updated 117 days ago
(1 Entries , last by Jason.B4 )

Blog
Nothing New Since Your Last Visit
7141
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
20. VB Classic Prevent Derivation (Not Supported)

VB Classic supports a form of single level inheritance where you, in essence, create an abstract class and then implement it in one or more classes that inherit from the abstract class. However, you cannot have any further descendant classes so "prevent derivation" is implemented by design of this simple inheritance model.

12 years ago, and updated 11 years ago

Code
Nothing New Since Your Last Visit
5936
Hits

C# (Visual C# & VS.Net)

Icon Legend:
Recent or not:
- Recent activity (within last two weeks).
- No activity last two weeks.
 Since your last logged visit:
- New to you or updated since your last visit (sign in now to activate).
- NOT new to you since your last visit (sign in now to activate).

New C# (Visual C# & VS.Net) Knowledge Base Post...

Share your knowledge with the WORLD! In addition to adding comments to existing posts, you can post knowledge you've acquired. We welcome full articles (intro with screen shots), general posts (shorter), and tidbits (tips, FAQs, definitions, etc.).

Post New...

Tidbit Post: Short Flashcard FAQ Definition Quick Tip Code Snippet
Longer Post: Full Article General Post File Link Error News
Other: Blog Topic
Or, if YOU have a question...
  C# (Visual C# & VS.Net) Message Board

Follow PrestwoodBoards on: 


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