|
Hi new to programming. I have a program that is supposed to compare two dates however when I run the program it reads the date as a string. What is the best way to compare a date to another date?
|
|
|
|
|
Use DateTime.Parse to parse a string into a DateTime (be sure to catch exceptions) and use DateTime.Equals or == to compare it to another DateTime . If you only want to account for the date portion of a DateTime , then compare one DateTime.Date to another. Same goes for DateTime.TimeOfDay (which is actually a TimeSpan structure). See the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
:-Dusing System;
namespace ConsoleApplication3
{
class Class1
{
static void Main()
{
//this is two date and the dateTime.Compare
//method will return 0 if both data are equal
//otherwise it will return 1
DateTime dt=new DateTime(2004,06,05);
DateTime dt1=new DateTime(2004,03,05);
int a=DateTime.Compare(dt,dt1);
Console.WriteLine(a.ToString());
//please don't use any other data type to reprasent datatime data types.
}
}
}
hai, feel free to contact
Sreejith SS Nair
sreejith@neosoft-tec.com
|
|
|
|
|
|
See the BitConverter class in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My class has a structure as such:
public class MyClass{
MyNestedClass Property1;
string Property2;
(... other members ...)
protected class MyNestedClass{
string PropertyA;
string PropertyB;
(... other members ...)
}
}
The reason behind encapsulating PropertyA and PropertyB is because I use the two properties more often than the other members in MyClass, even though PropertyA and PropertyB belong (describe) MyClass. That reason seems to be good when it comes to implementation.
However, somehow I don't think it is conceptually correct because I believe that a class should describe a complete entity.
I appreciate any comments.
|
|
|
|
|
Hi,
I am trying to create a login page.
Can someone point out to me how I may connect to a back-end Access database, and validate the entered username and password with the ones stored in the database?
Thanks for any help in advance
|
|
|
|
|
See my article, Role-based Security with Forms Authentication[^], for information on how to use a database to store and validate credentials using Forms Authentication, which provides many features over most home-brewed solutions (which are typically pretty insecure if you don't have a lot of experience with security).
The .NET Framework 2.0 will make this even easier with pluggable authentication back-ends to various front-ends (like Forms Authentication). For now, you're pretty much left with either extending what's available or implementing your own authentication modules.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Making my application i have suddently got and evil optimization question about "What are the internals of the array list" . Does any of you know if it is based on a linked list or on an array.
Also do you know where i can get my hand on a Simple Linked List or a Binary Tree.
Thank you for help.
|
|
|
|
|
An ArrayList is an array that grows dynamically by recreating the array (often doubling the size) everytime the bounds are surpassed.
As far as binary trees go, I suggest you take a peak at the MSDN article[^] regarding data structures. Part 3[^] of the article shows off some trees, including the source for a binary tree in C#.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
As Judah said, it uses a new array that typically doubles whenever the Capacity is reached.
To note, the ArrayList is used internally by many collections, so don't think you can escape it so easily!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank both of you.
I have another little question. What is the perforamce loss due to the type casting of array list elements. If my array list contains the same type elemets (or which share the same base class), could i use something equivalent to templates in C++.
Thank again.
Anton.
|
|
|
|
|
An ArrayList stores object s, so if you add reference types to the list, there's really no performance hit (1 to 2 extra instructions are required to cast, and optionally store, your type, but that's negligible). If you store value types, there is a slight performance hit because value types must be boxed and unboxed to store as an object . This is one of many reasons why generics will be great to have in the upcoming .NET Framework 2.0. Then you can declare a new list of value types, like List<int> ints = new List<int>(); .
This (un)boxing is typically not too big a problem if you don't use it a lot and don't need to milk your app for performance for every last drop. If you do, then you might consider implementing your own ArrayList -like class, implementing all the same interfaces (for the best support) and keep an array of whatever value type you need. Grow it when needs be, just like the ArrayList would.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In this case i will keep it, since making changes later would be much easier.
Thank you.
|
|
|
|
|
I have several images that have text on them, they are instructions that were turned into jpegs. Here is the question is there a way to de-construct the image so I can get just the text?
The reason for this insanity is reports. I have a report that "could" have lots of image data and as we all know there is no good way to split an image for a page break. Is there a good way to do this?
I will be coding for IE 6 only as this is an internal project, so x-browser solutions are not required .. but always welcome..
Any help on this would be great.
Thanks
William O'Malley
|
|
|
|
|
|
thank you for the article reference. very interesting stuff.
How ever I really don't have the money to spend on a third party add in. I was really hoping that I could find a way to do this with out using a third party add-in
thanks
William O'Malley
|
|
|
|
|
You don't need third-party software: the article describes how to create your own OCR scanning solution. However you implement, the concepts around OCR are your solution.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
i use cards.dll to draw cards in my app.
and it works good in onpaint method
for example:
<br />
Graphics x = e.Graphics;<br />
<br />
hdc = x.GetHdc();<br />
x.ReleaseHdc(hdc);<br />
cardHandle.drawCardBack( hdc, 90, 10, eBACK.WEAVE1 );<br />
but if i try do the same thing offscreen, it does not work!
can someone explain why?
<br />
Bitmap offScreenBmp = new Bitmap(this.Width, this.Height); <br />
Graphics offScreenDC = Graphics.FromImage(offScreenBmp); <br />
<br />
hdc = offScreenDC.GetHdc();<br />
offScreenDC.ReleaseHdc(hdc);<br />
cardHandle.drawCardBack( hdc, 90, 10, eBACK.WEAVE1 );<br />
e.Graphics.DrawImage(offScreenBmp, 10, 10);<br />
I need it to rotate this card.
I have tried this method, but it does not worke.Graphics.RotateTransform(90f);
if u know another way how to rotate the card i draw with cards.dll, please tell me
thank u
|
|
|
|
|
It probably doesn't work because you're releasing the HDC before you use it. Release it afterward. Once you've drawn to an off-screen bitmap, you should have no problems rotating it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
oh, u r right, it works!
but, what's about this first example?
it seems as if it works pretty good!
|
|
|
|
|
Surprising that it does, but you really shouldn't release the HDC until you're done (that's how it supposed to work).
See the native CreateCompatibleBitmap API. You probably need to create a bitmap that is compatible (i.e., supports the same capabilities) with the on-screen bitmap, which is usually the case in GDI. You might be able to accomplish this by using Graphics.FromHdc to get a Graphics object, then use Clone to clone it. I've never tried it this way, but GDI+ is usually as simple as this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I need to know what is the fastest and most efficient way to upload large files (4mb to 50mb) from a c# windows form app to a win2k server. I've run into memory issues on my server with files larger than about 8m (iis caches the entire file uploaded as a byte array before writing to disk ... this causes the server to hang) and need to implement a solution to this problem.
I've fished around for a chunking solution (send the file up in, say, 500k chunks and rebuild the file on the server) but cant find any code examples on how to do this.
Any help would be greatly appreciated.
Rob
(first time poster, long time reader )
|
|
|
|
|
Sorry, but what's wrong with the System.IO.File.Copy method?
I see dumb people
|
|
|
|
|
The upload is from a windows form application to a win2k server over the internet, so its not a simple file copy over an internal lan.
|
|
|
|