|
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.
|
|
|
|
|
Luc Pattyn wrote: Unless there are too many of them
That would be confusing. It would become evil if you'd try to justify it by calling it obfuscation
Quoad vos spirum, vos sperum?
|
|
|
|
|
I was thinking that would be the one case (obfuscation) of good justification for too many globals.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
One thing to note about this example is that it's not a singleton. It's a global property called Instance that is accessed via the EnterMineAndDigForGold class.
The key point about a singleton is that there is only one instance at any point in time and there can never be more than one. There is nothing stopping me from ignoring the Instance property on EnterMineAndDigForGold and creating as many instances of EnterMineAndDigForGold as I want.
In order to make this a singleton you would need to make sure that no-one can create any instances of EnterMineAndDigForGold other than the one created and held as the static variable _instance.
The easiest way to do this is to make the constructor for EnterMineAndDigForGold private. That will stop any other class from creating one of these.
To be honest, looking at your class I don't think it really matters because your EnterMineAndDigForGold class doesn't have any instance state so it doesn't matter whether you create a new one every time, or share one around, or make all the methods static so that you never need an instance at all.
|
|
|
|
|
Singletons are unnecessary (though not necessarily evil) in C#, especially since the advent of static classes.
Only use singletons in lesser languages; like C++.
|
|
|
|
|
What is the best way to determine an Object Variable is null or Empty ?
(or is not Null and Empty)?
|
|
|
|
|
I know the best method for checking null, and that is very simple.
Just compare your object with null keyword.
if(obj==null)
{
}
But for checking emptiness of your object you need to prepare custom method
of your object and check emptiness of all member.
Class Employee
{
String FirstName;
String LastName;
public bool IsEmpty()
{
if(!String.IsNullOrEmpty(FirstName) || !String.IsNullOrEmpty(LasttName))
return False;
else
return True;
}
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
If it's a string then use string.IsNullOrEmpty .
If it's for another class then it depends on how you define empty. If this is for your own classes you could define an IEmpty interface and implement that.
public interface IEmpty
{
bool IsEmpty { get; }
}
then you can use a generic method such as
public static bool IsNullOrEmpty<T>(T obj) where T : IEmpty
{
if (obj == null)
return true;
return obj.IsEmpty;
}
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)
|
|
|
|
|
Thanks
Will You Please Give me an example on how to use this codes.
|
|
|
|
|
OK, here's an example class. The implementation of the interface is the method at the end.
public class IntString : IEmpty
{
private string text;
private int value;
public IntString()
: this(0, string.Empty)
{ }
public IntString(int value)
: this(value, string.Empty)
{ }
public IntString(string text)
: this(0, text)
{ }
public IntString(int value, string text)
{
this.text = text;
this.value = value;
}
public string Text
{
get { return text; }
set { text = value; }
}
public int Value
{
get { return value; }
set { this.value = value; }
}
public bool IsEmpty
{
get { return value == 0 && string.IsNullOrEmpty(text); }
}
}
To use it, combined with the method and interface declaration i posted earlier you can do something like this...
IntString intString = new IntString();
Console.WriteLine(IsNullOrEmpty<IntString>(intString));
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)
|
|
|
|
|
Thanks for reply,
I think that u didnt get my question:
I wanna something like :
Object objVariable;
if(!String.IsNullOrEmpty(objVariable))
Instead of doing this :
Object objVariable;
if(objVariable !=null && objVariable.ToString() !="")
|
|
|
|
|
As I posted above[^] then
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)
|
|
|
|
|
Thanks
Will You Please Give me an example on how to use this code.
|
|
|
|
|
you could say that again.
|
|
|
|
|
We could be heading for infinite recursion here
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)
|
|
|
|
|
Hi,
As an alternative, you could create an extension method to perform the check;
internal static class UtilityMethods
{
internal static bool IsEmpty(this object o)
{
return o == null;
}
} This would result in code that looks like this;
Object objVariable;
if(!objVariable.IsEmpty())
{
}
I are Troll
|
|
|
|
|
How to populate row number for datagridview in row header column with out any looping statements?
it will be very usful for me if you help.
Elango.N
modified on Tuesday, June 15, 2010 5:51 AM
|
|
|
|
|
You can implement your custom datagridview by overriding it and then use it's OnRowPostPaint method
to draw row number.
That's it. No whenever you use this grid it will automatically add row number to the datagridview.
This is the simplest solution I have to apply row number in datagridview without any kind of looping.
class MyDGV : DataGridView
{
public MyDGV()
{
}
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
{
string strRowNumber = (e.RowIndex + 1).ToString();
while (strRowNumber.Length < this.RowCount.ToString().Length) strRowNumber = "0" + strRowNumber;
SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
if (this.RowHeadersWidth < (int)(size.Width + 20)) this.RowHeadersWidth = (int)(size.Width + 20);
Brush b = SystemBrushes.ControlText;
e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
base.OnRowPostPaint(e);
}
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
I have a project for antiquity which need saving pictures and maps for specific impression.I search alot but articles often speak about saving path of picture in sgl.can anybody help me?
|
|
|
|