|
For some reason DateTime.DaysInMonth(2008, 4) returns 31, yet DateTime.Parse("2008-04-31") yields in a FormatException.. am i missing something here? or is this some sort of bug.
|
|
|
|
|
damianrda wrote: am i missing something here?
Yeah, how to create a subject line that is meaningful and descriptive.
only two letters away from being an asset
|
|
|
|
|
Running the line of code you just mentioned returned 30
<br />
MessageBox.Show(DateTime.DaysInMonth(2008, 4).ToString());<br />
<code><br />
<br />
Sorry not much help there but I just thought id give you the result of my test. Very strange that it is returning 31 - it doesnt seem possible.
|
|
|
|
|
Yeah, I assumed he fat fingered the date and meant March, but if you're talking about April - yeah...that's a problem ;D
|
|
|
|
|
Aside from the bad subject line, I'd say your problem is that its parsing your date assuming a YYYY-DD-MM format.
|
|
|
|
|
damianrda wrote: am i missing something here?
Yes what Mark said and the fact that those two methods you posted have nothing to do with each other so your post is like saying, for some reason you can eat potatoes yet jumping off a building will hurt you.
led mike
|
|
|
|
|
led mike,
How tall is this building everyones jumping off?, I hope its not too big..
Regards,
Gareth.
|
|
|
|
|
I want a method to return different data types or classes. For example, sometimes I want the method to return an integer and sometimes I want it to return a string. I can do this by letting the method return an object and then the calling function has to cast the object into the appropriate type. Can I somehow make the calling function automatically find out which class or types it belongs to and "cast itself" into the appropriate type? Basically, this is what I want to do:
object myObject = myMethod(); // Can return an int or a string, casted into an object
MessageBox.Show("" + (myObject.GetType()) myObject); // Should work for both int:s and string:s
I want the expression
(myObject.GetType())
to be interpreted as a cast. How can I accomplish what I want?
Note: I've simplied the problem in order to make it easy to understand. Using ToString won't solve my real problem.
|
|
|
|
|
That kinda defeats the point of a strongly typed language. why would you ever want to do that?
(As far as I'm aware a dynamic cast like that isn't possible. you wouldn't know at compile time what type of object it was, so all it could be assigned to would be an Object type, so you'd instantly lose the cast Feel free to correct me if anybody knows better)
You'll probably find your problem is better solved by redesigning the class hierarchy your using, or using Generics instead.
Post a bit more detail so I can try to understand why you need to do this.
Simon
|
|
|
|
|
if you know it can be either string or int, you can always try
if (myObject is string)
SlayFourInnocentSheep( (string) myObject );
else if(myObject is int)
MessageBox.Show("It is an int!");
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
|
|
|
|
|
This sounds like a job for Generics. Are you on a 2.0 or above platform? If not you should be. If you are then study Generics.
led mike
|
|
|
|
|
Thanks for your suggestions. I tried to use Generics, but couldn't get it to work. However, I should probably start a new thread for that problem.
modified on Wednesday, April 2, 2008 7:56 AM
|
|
|
|
|
Hi,
In C#, How to check current date falls between start date and end date.
start date and end date are defined in Database. so I want to check whether current is in between start and end date.
Can any one help me.
Thanks.
|
|
|
|
|
// Load start date and end date from database.
if(currentdate > startdate && currentdate < end)
{
// current date is between start and end date.
}
else
{
// It's not.
}
[EDIT]
(You can get the current date by doing DateTime.Now)
[/EDIT]
Simon
modified on Tuesday, April 1, 2008 12:26 PM
|
|
|
|
|
DateTime.Compare() method returns -1 if the date is less than the value compared to, +1 if greater and 0 if the same.
public bool TestDateWithinBounds(DateTime StartDate, DateTime EndDate, DateTime DateValue)
{
if (DateValue.CompareTo(StartDate) == -1)
return false;
if (DateValue.CompareTo(EndDate) == 1)
return false;
return true;
}
Dave
|
|
|
|
|
I don't know why anyone would vote your answer down. it looks good to me. Here, have a 5.
Simon
|
|
|
|
|
Thanks
Dave
|
|
|
|
|
Hi, I try use a number (decimal) wrote in a commandline of my program.
I use
string args = System.Environment.CommandLine;
and args shows "PathofMyApp\NameofMayApp.exe" .7 --------> .7 is a commandline argument
I need use this .7 in a line
this.Opacity = varWhenIsTheDecimalNumber;
I resume. I need a way to use the .7 .8 .5 .2 or .AnyNumber
I hope that somebody understand me
Thanks,
|
|
|
|
|
Hi,
I would:
- call Environment.GetCommandLineArgs() to get all the parts of the command line
as a string array (the first part will be the path of the executing EXE),
- check the number of elements in that array
- use Decimal.TryParse() to parse the decimal argument
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.
|
|
|
|
|
Hi, Luc, thanks for your answer, I tried but I am very inexpert (supernewbie is my first day with C#), and cannot works.
I declared
string[] args;
Follow I call:
args = Environment.GetCommandLineArgs();
But, how do I use it? this.Opacity use 'double' format data and Enviroment.GetComandLineArgs give me 'string[]' data. I am very confused .
Ok, thank new and again, I search more and maybe learn more. If you have some additional tips, Thanks a lot!!!!
Bye
|
|
|
|
|
Hi,
a command line is just text, so it is only natural Environment.CommandLine
and Environment.GetCommandLineArgs return one or several strings.
to interpret a textual representation of some data, you need to "parse" it;
most primitive data types provide a Parse() and TryParse() method for exactly that
purpose.
if you need a double, and your input format is likely to be in an acceptable format
for it (as in .7), then just do bool success=double.TryParse(myString, myDouble)
When in doubt, look it up; the documentation is eager to be your friend.
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.
|
|
|
|
|
bool success=double.TryParse(myString, out myDouble)
|
|
|
|
|
you know that, I know that; however I'm not in the spoon feeding business,
I am plugging documentation here.
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.
|
|
|
|
|
Very thanks!!!!!!!!!!!
It works very good
<br />
args = Environment.GetCommandLineArgs();<br />
double.TryParse(args[1], out d);<br />
this.Opacity = d;<br />
Now I will make that when the argument in the commandline don't exist, set a default Opacity 1.0.
I will try.
Thanks, Bye
|
|
|
|
|
Hello Friend!
I've built a windows application.
now I want to show any gif image while system is busy to save data in data base. after completing save operation the image will be invisible. again it will be visible during saving data.
How can I do this?
Please, help me.
Thanks!!!!!!!!!!
|
|
|
|