|
Hi Jeff,
you should try not to rely on type names, since doing so will fail for derived types.
The way to go most often is using the "is" or "as" keywords, as in:
if (obj is Font) {
... do someting fonty (probably will need a cast)
} else if (obj is Panel) {
... deal with a Panel (probably will need a cast)
} etc.
or
Font fnt=obj as Font;
if (fnt!=null) {
... do someting fonty to fnt (no extra cast required)
}
Panel pan=obj as Panel;
if (pan!=null) {
...
}
The above will also match mySpecialPanel and the like, something typename-dependent code
would typically not do.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
You could also use some lookup pattern.
setup type -> action association
Dictionary<type, somedelegate> myLookup = new .....
myLookup.Add(typeof(string) , () => MessageBox.Show("Its a string!"));
myLookup.Add(typeof(int) , () => Console.WriteLine("ooh an int.."));
and then replace your switch/if with:
------
SomeDelegate action;
if (myLookup.TryGetValue( a.GetType() , out action ) )
{
action();
} ----
So you replace your switch/if completely with the lines above...
But it depends on what you actually want to accomplish.
See the post above mine regarding subclasses.
|
|
|
|
|
hi ,
i've defined a class named vector that it includes two Points and one void for drawing that and ..., i just want to know how can i find the angle between two vectors that start from one point?,
does anyone know know it's code (for C#)
|
|
|
|
|
Did you try searching Google? First find out formula for finding the angle and then write corresponding c# code.
|
|
|
|
|
|
You mean this?
Y1 Y2
| /
| /
| /
| /
|α/
X
You want to find the angle Α between vector Y1 and Y2?
If so convert the points to vectors (like you said) and subtract the angles, then you have the angel between the points.
α = Y1∠θ - Y2∠θ
If you mean you have something like this:
Y1_________________________________________Y2
\ /
\ /
\ /
\ /
\_________________________________/
Y3 Y4
X
Where you are looking for a part of the circle (the lines between Y1,Y2 and Y3,Y4 are arcs from the circle drawn from radius from circle( (Y1)∠θ ) - circle ( (Y3)∠θ ) sectioned between Y1∠θ and Y2∠θ
|
|
|
|
|
Hello,
I have some gawk scripts that i want to run in C# code.
Is it possible?
|
|
|
|
|
You can achieve the same goal using Regular Expressions. But this would mean rewriting those gawk scripts.
Just because we can; does not mean we should.
|
|
|
|
|
Greet to all
I am facing problem in accessing data of ms word to my project of c sharp .net 2005
I want to access the data word wise so that I can put it in Sql table
hoping for the good reply from you all
thanks
|
|
|
|
|
You can use Word Object Model to get the data from ms word document
|
|
|
|
|
|
|
|
thanks but I don't want to install another word package apose.word
But yes thanks
|
|
|
|
|
welcome.i think frist link help to u
Cheers
RRave
MCTS,MCPD
|
|
|
|
|
Sorry for bother so I change my question please tell me
where can I find some speech recognition classes or how do I use a specific class to recognize speech.Keep in mind i am working with visual c#.net2005.
|
|
|
|
|
Editing your previous post would have been a better idea. Did you try searching Google[^]?
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
i trying to search it from google but still i have not found .
|
|
|
|
|
Look at some of the content from the link in my OP. You will find something useful there.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
What do you mean by my OP Please explain it.Where I find your OP.
|
|
|
|
|
OP == Other Post. So click the link in his first response to your question.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Skippums wrote: OP == Other Post
ROTFLMAO Which "other post"?
led mike
|
|
|
|
|
OK, maybe it meant "Original Post", or "Original resPonse", or "Oldest resPonse to this question". I don't know what the hell OP was really meant to stand for, but using context clues I worked out that he meant his first response on this thread.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
when i was searching for socurce code for speech recognition in google.I found this site so i requist for sample source code.Becouse from sample source code i can better understand how make a speech recognition softwere.
|
|
|
|
|
faisalid2000 wrote: socurce
faisalid2000 wrote: requist
faisalid2000 wrote: Becouse
faisalid2000 wrote: softwere
I hope your speech recognition software is better at recognising your speech than my character recognition software is at recognising your words.
so you answer don't be scared of failure
The only failure is never to try
Things You've Never Done - Passenger -2008
|
|
|
|