Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to put imagens randomly? Pin
RobCroll31-May-11 13:15
RobCroll31-May-11 13:15 
QuestionRectanlgeF.Parse(string s) extension method? Pin
Chesnokov Yuriy31-May-11 1:58
professionalChesnokov Yuriy31-May-11 1:58 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Not Active31-May-11 2:03
mentorNot Active31-May-11 2:03 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Chesnokov Yuriy31-May-11 2:22
professionalChesnokov Yuriy31-May-11 2:22 
AnswerRe: RectanlgeF.Parse(string s) extension method? [modified] Pin
musefan31-May-11 2:26
musefan31-May-11 2:26 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
Pete O'Hanlon31-May-11 2:33
mvePete O'Hanlon31-May-11 2:33 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
musefan31-May-11 2:42
musefan31-May-11 2:42 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn31-May-11 2:42
sitebuilderLuc Pattyn31-May-11 2:42 
yes and no.

Extension methods, while requiring a static keyword, are really instance methods; now Parse and TryParse are basically static methods, they operate on a string and return a specific type, they don't operate on that type (the MSDN example is string.WordCount which operates on an existing string and returns an int).

So you could have this definition (note the first argument isn't used at all):
public static class MoreTryParse {
	public static bool TryParse(this RectangleF dummy, string s, out RectangleF rect) {
		float x=0;
		float y=0;
		float w=0;
		float h=0;
		if (s.StartsWith("(") && s.EndsWith(")")) s=s.Substring(1, s.Length-2);
		string[] sa=s.Split(',');
		if (sa.Length==4 && float.TryParse(sa[0], out x) && float.TryParse(sa[1], out y) &&
			float.TryParse(sa[2], out w)&& float.TryParse(sa[3], out h)) {
			rect=new RectangleF(x, y, w, h);
			return true;
		} else {
			rect=new RectangleF(0, 0, 0, 0);
			return false;
		}
	}
}


but then you would have to call it like this:
public void test(string s) {
	RectangleF rect=new RectangleF();
	bool result=rect.TryParse(s, out r1);
	log(s+"  result="+result+"  rect="+rect.ToString());
}

which is a bit silly, as you have to create a dummy RectangleF in order to get the actual one.

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Please use <PRE> tags for code snippets, they improve readability.
CP Vanity has been updated to V2.3

AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Chesnokov Yuriy31-May-11 2:47
professionalChesnokov Yuriy31-May-11 2:47 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn31-May-11 2:55
sitebuilderLuc Pattyn31-May-11 2:55 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
BobJanova31-May-11 3:04
BobJanova31-May-11 3:04 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn31-May-11 4:00
sitebuilderLuc Pattyn31-May-11 4:00 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
BobJanova31-May-11 23:09
BobJanova31-May-11 23:09 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn1-Jun-11 0:17
sitebuilderLuc Pattyn1-Jun-11 0:17 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Shameel31-May-11 3:05
professionalShameel31-May-11 3:05 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
Pete O'Hanlon31-May-11 3:39
mvePete O'Hanlon31-May-11 3:39 
QuestionClicking a button with SendMessage [modified] Pin
musefan30-May-11 23:36
musefan30-May-11 23:36 
AnswerRe: Clicking a button with SendMessage Pin
Shameel31-May-11 0:15
professionalShameel31-May-11 0:15 
GeneralRe: Clicking a button with SendMessage Pin
musefan31-May-11 0:42
musefan31-May-11 0:42 
GeneralRe: Clicking a button with SendMessage Pin
Shameel31-May-11 0:55
professionalShameel31-May-11 0:55 
GeneralRe: Clicking a button with SendMessage Pin
Shameel31-May-11 0:58
professionalShameel31-May-11 0:58 
GeneralRe: Clicking a button with SendMessage Pin
musefan31-May-11 2:22
musefan31-May-11 2:22 
AnswerRe: Clicking a button with SendMessage Pin
Pete O'Hanlon31-May-11 2:43
mvePete O'Hanlon31-May-11 2:43 
GeneralRe: Clicking a button with SendMessage Pin
musefan31-May-11 5:59
musefan31-May-11 5:59 
AnswerRe: Clicking a button with SendMessage Pin
_Erik_1-Jun-11 4:20
_Erik_1-Jun-11 4:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.