|
Thanks, Luc. There was a page in the MSDN after all - under the "DateTime" member of the "DateTime" class (I may never understand this terminology):
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref2/html/O_T_System_DateTime_.ctor.htm
|
|
|
|
|
You mean, kinda like this:
DateTime myTime = new DateTime(1945, 10, 5, 13, 7, 0, DateTimeKind.Utc);
?
EDIT: Alas, beaten to it.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Yes, I was "baffled" by the word "constructor" in the help files, apparently. Oddly enough, there's no examples of creating DateTime in any of the examples and sample code. Just deconstructing and converting them.
Your favorite word is now "baffle", although "lennet" is still pretty good.
|
|
|
|
|
JoeRip wrote: I was "baffled" by the word "constructor"
yes, also value types have constructors.
It is correct, but not very useful, to write int a=new int(7); ;
it is useful to use constructors on structs, such as DateTime.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yes, I'm way too used to using .Net objects without really understanding what they are. I see all these properties like DateTime.Hour which I can *get*, and I assume that I can *set* them, too.
Of course, the values in DateTime can only be set when they are initialized, but that wasn't occurring to me. So I was using new DateTime() , and trying to set the individual properties.
Intellisense would have shown me the constructors for "new DateTime( " if I had been paying attention, but clearly I was not.
|
|
|
|
|
Hi,
I've developed a C#.NET webservice. Is it possible to schedule it.
Also If Download is one of the operation performed by the web service
can i use the url : http://localhost/FileDownload/Service.asmx/Download?
Thanks in advance
Priya
|
|
|
|
|
Dpriya wrote: I've developed a C#.NET webservice. Is it possible to schedule it.
Also If Download is one of the operation performed by the web service
can i use the url : http://localhost/FileDownload/Service.asmx/Download?
This is a copy and paste from a post in the ASP.NET forum[^]. Are you aware that cross posting is considered rude by many people?
|
|
|
|
|
How do I run constructor without calling it's method's C# ?
for example:
class A
{
private static A _instance=new A();
private A()
{
SomeSingleTonClass.Instance.Items.Add(this);
}
public static A
{
get
{
return _instance;
}
}
}
thanks.
Dima
-- modified at 18:58 Monday 29th October, 2007
|
|
|
|
|
You might want to look at this implementation of a singleton: http://blog.colinmackay.net/archive/2007/09/05/393.aspx#395[^]
The version I have in the main blog entry is fine for single-threaded applications. The version in the comment is thread-safe.
Essentally you need to call the constructor in the public static property.
|
|
|
|
|
Now you've modified your post...
Dima.HEMEHT wrote: How do I run constructor without calling it's method's C# ?
The constructor will run when it needs to. Do you want the constructor to run at an explicit time? And if so why?
Actually, what are you trying to do with this class? It doesn't make sense...
|
|
|
|
|
Colin Angus Mackay wrote: Now you've modified your post...
Oh, that's why it didn't make any sense...
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Guffa wrote: Oh, that's why it didn't make any sense...
I don't think it made much sense the first time round either. I interpret these things as best I can...
|
|
|
|
|
The constructor will run when it needs to.- This is my problem.
I want to make abstract class, which will register it self in any collection.
But because Just In Time feature .Net runs constructor only when I reference to class.
public class MyTypesCollection //singleton
{
...
}
public abstract class TypeBase
{
public TypeBase(String name)
{
MyTypesCollection.items.add(name,this);
}
}
public MyNewType: TypeBase
{
private static _instance=new MyNewType("MyType");
public TypeBase(name as string):base(name)
{
....
}
}
If this code were used in JAVA it were initialize by itself , cause JAVA doesn't have JIT
|
|
|
|
|
Dima.HEMEHT wrote: I want to make abstract class, which will register it self in any collection.
But because Just In Time feature .Net runs constructor only when I reference to class.
That has nothing to do with the JIT compiler. The C# compiler compiles into IL code, and the purpose of the JIT compiler is to create the native machine code when the application is executed.
It's defined in the language when the values for the static members are created. It's only specified that the static constructor (which will create the object for the _instance variable) is executed before any members of the class is used. If your class is never used, the static constructor doesn't have to be executed at all.
Dima.HEMEHT wrote: cause JAVA doesn't have JIT
Yes, it does.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Ok i'm wrong.
What about answer?
|
|
|
|
|
I thought that was evident from my reply. It can't be done, as there is no guarantee that the static constructor will run if your class isn't used.
You could use reflection to loop through all the classes in all the assemblies, to look for classes that inherits your class.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
|
Hy
I want to put a variable like DateTime to a DataSet.
Is that possible and if ... how can I do that?
Can anybody help me?
thx
|
|
|
|
|
mihksoft wrote: I want to put a variable like DateTime to a DataSet.
Is that possible and if ... how can I do that?
Yes it is possible. Surely you just ensure the column type will accept DateTime object and assign the value appropriately. What code have you written and what problems are you having with it? (I assume, of course, that you have actually tried this and somehow it doesn't work. I'd be most disappointed if you hadn't done the most basic research before asking here)
|
|
|
|
|
I did it !
|
|
|
|
|
I always get an argumentexception on the following code, and I don't know why.
bmp = new Bitmap(typeof(Form1), "toProcess.bmp"); //Read an image from hdd
MemoryStream mstream = new MemoryStream();
bmp.Save(mstream, ImageFormat.Jpeg); //Save image into MemoryStream in jpeg
jpegByteArray = new byte[mstream.Length];
mstream.Read(jpegByteArray, 0, (int)mstream.Length); //Read mstream into byte[]
MemoryStream jpegStream = new MemoryStream();
jpegstream.Write(jpegByteArray, 0, jpegByteArray.Length); //Write byte[] back to another MemoryStream
jpegstream.Position = 0;
Image newimg = Image.FromStream(jpegstream); //THIS throws an ArgumentException
I checked in debugging mode and every variable has the exact same number of bytes, and if I only save the image into a stream and read it right back, then it works. Please save me from pulling my hair out and shoot me with any help you can think of!
-- modified at 18:50 Monday 29th October, 2007
|
|
|
|
|
using System.IO;
private byte[] bImage;
private string strImagePath;
private FileStream objFileStream;
private MemoryStream objMemoryStream;
private Image objImage;
private void convertImageToByteArray()
{
strImagePath = "C:\\toProcess.bmp";
objFileStream = new FileStream(strImagePath, FileMode.OpenOrCreate, FileAccess.Read);
bImage = new byte[objFileStream.Length];
objFileStream.Read(bImage, 0, Convert.ToInt32(objFileStream.Length));
objFileStream.Close();
}
private void convertByteArrayToImage()
{
objMemoryStream = new MemoryStream(bImage);
objMemoryStream.Flush();
objImage = Image.FromStream(objMemoryStream);
objMemoryStream.Close();
}
|
|
|
|
|
Thank you! In the meantime I managed to solve my problem. Instead of using
mstream.Read(jpegByteArray, 0, (int)mstream.Length);
to read the MemoryStream's content into the byte[] I should have used
jpegByteArray = mstream.ToArray();
Don't ask me why this works and the other method doesn't, thereotically both should work. Anyway, I had to do this using only in-memory objects, because this is for realtime video stream processing.
Cheers
-- modified at 6:51 Tuesday 30th October, 2007
|
|
|
|
|
Hi
I have created dll using C# and add reference to another project that was written in VB.net.
so I have two project, one is using C#, the other one is using VB.net. Both written in Visual Studio.net 2005.
When I set break point of my function from dll project because that's what I want to debug.
So I started running CallingDll VB project in debug mode, I got following message
<br />
The following module was built either with optimizations enabled or without debug information:<br />
C:\myDll.dll<br />
<br />
To debug this module, change its poject build configuration to Debug mode. To supress this message, disalbe the "Warn if no user code on launch" debugger option.<br />
Where should I change it?
I went to Project\Properties, I couldnt' find anything that said Debug Mode.
I looked into Debug, I found StartAction, Start Options, enable debuggers.
I changed put Start external program: "c:\CallDll.exe" and then build and run the project in debug mode. but I still got the same message and I couldnt' debug myDll.dll at all neither from myDll project nor callDll project.
I also looked into Build.. I dont 'see anything that is saying debug mode.
I check the MSDN and saying the same thing.. to change it to Debug mode. But where should I go and change it so myDll.dll can be debug.
I recreated myDll.dll and CallDll.exe using visual studio 2003. I had no prolem debugging. but not with visual studio 2005.
Would anyone please tell me how to debug myDll.dll from another project like CallDll??
Thanks
|
|
|
|
|
[Build][Configuration Manager] ?? Just a guess.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|