|
so what about this ?(I wanna to do this finally but dont know how to explain my question)
Object obj = null;
if(String.IsNullOrEmpty(obj))
{
}
obj = "";
if(String.IsNullOrEmpty(obj))
{
}
|
|
|
|
|
obj is not a string, so you cannot perform a string.IsNullOrEmpty on it. You need to test it with
if (obj == null) An Empty value is a special conditional value, and differs depending on the type it is appropriate for, so you cannot have a generic IsEmpty method that checks to see if it's empty.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You can create an extension method as has already been suggested but how do you expect to test for empty?
Unless ToString has been overridden to return string.Empty then obj.ToString() will never be empty.
namespace YourNamespace
{
public static class ExtensionMethods
{
public static bool IsNullOrEmpty(this Object obj)
{
if (obj == null)
return true;
}
}
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
it give these errors :
Error 1 Type expected
Error 2 ; expected
Error 3 Invalid token '==' in class, struct, or interface member
declaration
Error 4 Type or namespace definition, or end-of-file expected
Plz Help !!!!!!!!!!!!
|
|
|
|
|
Hello,
How I know Which computer locked my user?? Complicated?
Sombady knows ???
Thank-you.
|
|
|
|
|
You can't find that out. There is nothing in AD that logs or tracks that information.
|
|
|
|
|
Hi friends
I have a c++ dll which contains a class named as CLog. How can i use above class in C# program
thanks in advance
-kk.tvm-
|
|
|
|
|
If the C++ is .NET you can add a reference to the dll to your project and use the class directly.
If not, you will need to wrap it by recreating the functions of the class using the DllImport attribute[^].
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hey
Does anyone know how to view a jpg stored in a stream on a control such as a picturebox without having to first convert it to a BITMAP using Image.FromStream?
Thanx
|
|
|
|
|
why would one want that?
two ways:
1. save the stream to a file, then use Image.FromFile or PictureBox.Location
2. create your own JPEG decoder (the inverse of this[^], i.e. implement Image.FromStream yourself.
It doesn't make much sense to me.
|
|
|
|
|
Maybe I was a bit vague. I am recieving a stream of jpegs from a number of cameras. I want to show these on screen and I was wondering if there was a way of doing this without having to first uncompress the jpg using Image.FromStream as this is a slow process.
|
|
|
|
|
TimSWatson wrote: Maybe I was a bit vague.
indeed.
TimSWatson wrote: without having to first uncompress
when an image is visible on the display, you see individual pixels, hence it has been decompressed somehow somewhere. There is no way around that assuming a standard PC system is used. The only thing you could consider is creating your own JPEG decoder trading quality for speed; however you are likely to discover loosing quality is easier than gaining speed.
|
|
|
|
|
i'm communicating wiht a remote sever and i get a datetime as a long value, is there any method that converts the long to datetime directly...
|
|
|
|
|
There is no any direct way to convert long value to datetime.
You need to first convert it to string then you can convert to datetime.
Try following code for the same...
DateTime dateTime;
if (DateTime.TryParse(input.ToString(), out dateTime))
{
Console.WriteLine(dateTime);
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
prasadbuddhika wrote: i'm communicating wiht a remote sever and i get a datetime as a long value, is there any method that converts the long to datetime directly...
Depends on what encoded within that long-value. Is it a numerical representation of the date, like the number "12012002"? Or is it encoded as a number of days since a certain date?
I are Troll
|
|
|
|
|
Is the remote server returning you a Unix time by any chance? If so, you can convert it into a DateTime using:
DateTime localTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(unixTime).ToLocalTime(); This takes things such as Daylight Savings Time into account.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You need to make sure the number you have is a number of ticks, as defined by:
"(in .NET) time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calendar", so you may need a linear transformation;
You then can use the constructor new DateTime(long ticks)
PS: you do not need any string for this.
|
|
|
|
|
thanx for your replies ..
the date given by the sever is in this format "20100615072733" , i found a method
DateTime.TryParseExact(), and i tried following way , "s" contains the date value string
dateTime = DateTime.TryParseExact(s, "yyyy/MM/dd hh:mm:ss tt", CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dateTime);
but still i get the default date.
any help on this ...!
|
|
|
|
|
well, as the string doesn't have any / spaces or : characters it's not suprising.
Try:
DateTime dateTime = DateTime.ParseExact(s, "yyyyMMddhhmmss", CultureInfo.InvariantCulture, DateTimeStyles.None);
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
hey thanx Dave and all who helped me , exactly as u mentioned it works when the "/" are removed ... thanx..
|
|
|
|
|
yeah, when they put Exact in a method name, you'd have to be extra careful.
|
|
|
|
|
LOL!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
I try not to use global values as I belive that dependancys can be designed in a way that it should be dependant on as few objects as possible howeever I am making a small game and require some behavioural structure and came up with this:
public sealed class EnterMineAndDigForGold : IState<Miner>
{
static readonly EnterMineAndDigForGold _instance = new EnterMineAndDigForGold();
public static IState<Miner> Instance
{
get
{
return _instance;
}
}
public void Enter(Miner owner)
{
if (owner.Location != LocationType.Mine)
{
owner.Location = LocationType.Mine;
Console.WriteLine("Walked into the mine");
}
}
public void Execute(Miner owner)
{
owner.AddToGoldCarried(1);
Console.WriteLine("Picked up some gold");
owner.IncreaseFatigue(1);
Console.WriteLine("Getting more fatigued");
if (owner.PocketFull)
{
}
if (owner.IsThirsty)
{
}
}
public void Exit(Miner owner)
{
Console.WriteLine(owner.GetType().Name + " Is leaving the mine");
}
}
Which I have been learning from an AI book have learnt so far.
Is this ok to do?
modified on Tuesday, June 15, 2010 6:10 AM
|
|
|
|
|
"Global variables" were considered "evil", mainly because of the abuse - Singletons are not inherently evil.
Imagine people setting boolean flags to simulate communication between parts of the application
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: Singletons are not inherently evil.
Unless there are too many of them.
|
|
|
|