Click here to Skip to main content
15,885,914 members
Home / Discussions / C#
   

C#

 
Questionhow to check typ in string Pin
stephan_0071-May-08 22:46
stephan_0071-May-08 22:46 
AnswerRe: how to check typ in string Pin
Gareth H1-May-08 22:51
Gareth H1-May-08 22:51 
GeneralRe: how to check typ in string Pin
stephan_0071-May-08 23:13
stephan_0071-May-08 23:13 
GeneralRe: how to check typ in string Pin
J4amieC2-May-08 0:03
J4amieC2-May-08 0:03 
GeneralRe: how to check typ in string Pin
stephan_0072-May-08 1:19
stephan_0072-May-08 1:19 
AnswerRe: how to check typ in string Pin
dan!sh 1-May-08 22:54
professional dan!sh 1-May-08 22:54 
AnswerRe: how to check typ in string Pin
Bhim Prakash Singh2-May-08 0:01
Bhim Prakash Singh2-May-08 0:01 
AnswerRe: how to check typ in string Pin
Guffa2-May-08 2:56
Guffa2-May-08 2:56 
Why is the function using a string as parameter? That means that you have to convert all values to strings, then parse them back to the values again.

Make the parameter an object instead, then you can easily check the actual type of the value:

public int SomeFunction(object value) {
   if (value is DateTime) {
      DateTime d = (DateTime)value;
      ...
   } else if (value is double) {
      double d = (double)value;
      ...
   } else {
      throw new ArgumentException("Type "+value.GetType().Name+" is not accepted as parameter.");
   }
}


Using an object parameter to accept value types means that the values will be boxed. Boxing is something that you generally want to avoid if possible, but in this case there is no common base type between DateTime and Double that you could use instead. Also, converting to a string and back is far worse than boxing.

Despite everything, the person most likely to be fooling you next is yourself.

modified on Friday, May 2, 2008 9:04 AM

GeneralRe: how to check typ in string Pin
PIEBALDconsult2-May-08 8:26
mvePIEBALDconsult2-May-08 8:26 
QuestionC# Code Standards Pin
KBM731-May-08 21:10
KBM731-May-08 21:10 
AnswerRe: C# Code Standards Pin
Christian Graus1-May-08 21:18
protectorChristian Graus1-May-08 21:18 
AnswerRe: C# Code Standards Pin
Colin Angus Mackay1-May-08 22:18
Colin Angus Mackay1-May-08 22:18 
GeneralRe: C# Code Standards Pin
Vasudevan Deepak Kumar2-May-08 1:46
Vasudevan Deepak Kumar2-May-08 1:46 
AnswerRe: C# Code Standards Pin
Vasudevan Deepak Kumar2-May-08 1:44
Vasudevan Deepak Kumar2-May-08 1:44 
AnswerRe: C# Code Standards Pin
Kevin McFarlane2-May-08 4:05
Kevin McFarlane2-May-08 4:05 
QuestionSystem.Reflection GetValue method Pin
MrColeyted1-May-08 20:49
MrColeyted1-May-08 20:49 
AnswerRe: System.Reflection GetValue method Pin
Hesham Amin2-May-08 2:27
Hesham Amin2-May-08 2:27 
QuestionHow to read files that are locked exclusively by other applications? Pin
JohnsonDesouza1-May-08 20:17
JohnsonDesouza1-May-08 20:17 
AnswerRe: How to read files that are locked exclusively by other applications? Pin
N a v a n e e t h1-May-08 20:59
N a v a n e e t h1-May-08 20:59 
AnswerRe: How to read files that are locked exclusively by other applications? Pin
Christian Graus1-May-08 21:07
protectorChristian Graus1-May-08 21:07 
AnswerRe: How to read files that are locked exclusively by other applications? Pin
Luc Pattyn1-May-08 22:21
sitebuilderLuc Pattyn1-May-08 22:21 
Questionstatus strip - show some text Pin
lgatcodeproject1-May-08 20:17
lgatcodeproject1-May-08 20:17 
AnswerRe: status strip - show some text Pin
John Ad1-May-08 21:01
John Ad1-May-08 21:01 
QuestionRe: status strip - show some text Pin
lgatcodeproject1-May-08 21:32
lgatcodeproject1-May-08 21:32 
AnswerRe: status strip - show some text Pin
Thomas Stockwell2-May-08 10:39
professionalThomas Stockwell2-May-08 10:39 

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.