Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P32
(An Untitled Masterwork)
Active
Public
Actions
Authored by
stwalkerster
on Jun 15 2016, 2:55 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Tags
None
Referenced Files
F856:
Jun 15 2016, 2:55 AM
2016-06-15 02:55:16 (UTC+0)
Subscribers
None
// Let's have a class. It's sealed for some reason so we can't extend it.
public
sealed
class
Foo
{
// This class has two properties, but has nothing useful here.
public
int
Value1
{
get
;
set
;}
public
int
Value2
{
get
;
set
;}
}
// let's say I want to add the two numbers together. Because this is a Complicated Operation (tm), I'm gonna write an extension method to do it.
public
static
class
HandyStuff
{
public
static
int
SumThings
(
this
Foo
x
)
{
return
x
.
Value1
+
x
.
Value2
;
}
}
// let's get an instance...
var
foo
=
new
Foo
{
Value1
=
3
,
Value2
=
4
};
// Now, I can do stuff like this:
var
result
=
foo
.
SumThings
();
Event Timeline
stwalkerster
created this paste.
Jun 15 2016, 2:55 AM
2016-06-15 02:55:16 (UTC+0)
stwalkerster
updated the paste's language from
autodetect
to
csharp
.
•
import-bot
changed the edit policy from "All Users" to "
Community
(Project)".
Feb 3 2017, 3:03 PM
2017-02-03 15:03:45 (UTC+0)
Log In to Comment