|
ok, but after i want test if it is null.
with a object reference i cant test it, and i dont want reference the actual date.
|
|
|
|
|
There are 2 types of objects in .NET: reference types and value types. All classes are reference types. All structs are value types. All reference types can be assigned null. All value types cannot.
The reason for these 2 is for lightweight, fast stack-allocated values. For instance, System.Int32 , also aliased as int is a value type: you can pass it to a function which will actually pass a copy of the value.
Value types always must have a value; you can't assign them null, as that's not how value types work, nor should it be. Assigning an integer to null doesn't make sense, for instance. And since DateTime is a value type, you can't assign null to it.
Now, if you were using .NET 2.0, there is a new wrapper class called System.Nullable, where you can wrap a value type inside an object that can either be null or the value. Here's what that looks like:
Nullable<DateTime> nullableDateTime = new Nullable<DateTime>;
nullableDateTime = null;
nullableDateTime = DateTime.Now;
C# 2.0 has short-hand syntax for this, using the question mark:
DateTime? nullableDateTime = new DateTime?();
nullableDateTime = null;
nullableDateTime = DateTime.Now;
|
|
|
|
|
hey... thanks...
i`ve used a overloaded method to deal with this situation, instead of testing if a parameter is null or not.
great explanation... it was very instructive. :]
cya
|
|
|
|
|
tcss wrote: before using the datetime variable you must create it.
Not at all. DateTime is a value type, not a reference type.
---
b { font-weight: normal; }
|
|
|
|
|
Cut my teeth in C# with .Net 2.0. See comment below.
Thanks for correcting my post
|
|
|
|
|
The DateTime class is a struct and so can't be null. It's just like int, double, or one of the other value types, they can't be null.
|
|
|
|
|
pontonet wrote: WTF!
Why not learn more about the environment in which you are developing before exclaiming "WTF!". The difference between value and reference types is in any good beginners guide to .NET and/or C#.
|
|
|
|
|
sometimes we forgot the basic, even after read a lot of stuffs.
sometimes we are kinda influencied by other languages, like java.
a DateTime tends to be a real object instead of a value type - it has properties, methods, constructors, etc. so the difference isn`t so obvious.
|
|
|
|
|
If you're using C# 2.0 you can declare DateTime as nullable with the following:
DateTime? dataTermino = null;
if(txtDataInicio.Text != "")
dataTermino = DateTime.Parse(txtDataTermino.Text);
if(dataTermino != null)
insertCommand.Parameters.Add(new SqlParameter("@DataTermino", dataTermino));
(note the "?" after DateTime)would work. If you're not using 2.0 & need to pass null date to SQL , have a look at:
http://www.c-sharpcorner.com/Code/2003/Sept/EnterNullValuesForDateTime.asp[^]
Hope this helps
|
|
|
|
|
Does anyone know of an easy way to maintain a series of assembly 'reference paths' across a large number of projects.
I understand they are persisted in the proejct 'user' settings files. Initially i was wondering whether you could do something similar to a #Include in a xml. So at least they would only be stored once.
Cheers
Aj
|
|
|
|
|
what you want isn`t the same result achieved with a added DLL reference mapped directly to the user file system?
|
|
|
|
|
Hello,
How can I get all contents in RichTextBox and convert it to HTML format
My RichTextBox on winform. And I want to get it contents in HTML to sent it to my mail. But it doesn't work properly when I set BodyFormat = HTML.
Thank you,
ACB
-- modified at 12:25 Thursday 26th October, 2006
ngh
|
|
|
|
|
You could set it so it can only save as .htm(L)
|
|
|
|
|
I've used this in the past:
<pre> public string ToHTML(RichTextBox Box)
{
string sReturn;
long lColour;
bool bBold;
bool bItalic;
string sFont;
long lSize;
long lOldSelStart;
long lOldSelLength;
long a;
//Initial box setup
{
lOldSelStart = Box.SelStart;
lOldSelLength = Box.SelLength;
Box.SelStart = 0;
Box.SelLength = 1;
}
//Initial text
sReturn = "<html>";
//Inital paramaters
lColour = Box.SelColor;
bBold = Box.SelBold;
bItalic = Box.SelItalic;
sFont = Box.SelFontName;
lSize = Box.SelFontSize;
//Initial font setup
sReturn = sReturn + "<font size=\"" + Box.SelFontSize + "\" face=\"" + Box.SelFontName + "\" color=\"" + Box.SelColor + "\">";
//Initial bold setup
if (Box.SelBold == true)
{
sReturn = sReturn + "<b>";
}
//Initial italic setup
if (Box.SelItalic == true)
{
sReturn = sReturn + "<i>";
}
//Append new character
sReturn = sReturn + Strings.Mid(Box.Text, 1, 1);
for (a = 2; a <= Strings.Len(Box.Text); a++) {
//Set up reading paramater
{
Box.SelStart = a - 1;
Box.SelLength = 1;
}
//Check for updated font tage
if (Box.SelColor != lColour | Box.SelFontName != sFont | Conversion.Int(Box.SelFontSize) != lSize)
{
sReturn = sReturn + "</font><font size=\"" + Box.SelFontSize + "\" face=\"" + Box.SelFontName + "\" color=\"" + Box.SelColor + "\">";
}
//Check for changed boldness
if (Box.SelBold != bBold)
{
if (Box.SelBold == false)
{
sReturn = sReturn + "</b>";
}
else
{
sReturn = sReturn + "<b>";
}
}
//Check for changed italics
if (Box.SelItalic != bItalic)
{
if (Box.SelItalic == false)
{
sReturn = sReturn + "</i>";
}
else
{
sReturn = sReturn + "<i>";
}
}
sReturn = sReturn + Strings.Mid(Box.Text, a, 1);
//Update paramaters
lColour = Box.SelColor;
bBold = Box.SelBold;
bItalic = Box.SelItalic;
sFont = Box.SelFontName;
lSize = Box.SelFontSize;
}
//Check ending bold and italic
if (bBold == true) sReturn = sReturn + "</b>";
if (bItalic == true) sReturn = sReturn + "</i>";
//Terminate HTML
sReturn = sReturn + "</font></html>";
//Restore box values
{
Box.SelStart = lOldSelStart;
Box.SelLength = lOldSelLength;
}
return sReturn;
//Return value
}
</pre>
|
|
|
|
|
how can i get to know if a file is still copying?
thank you
|
|
|
|
|
Surely if you call
System.IO.File.Copy synchronously you'll know when it finishes when the call returns?
Regards,
Rob Philpott.
|
|
|
|
|
sorry that isn't what i want because i am not the coppier.
the file will be copied by someone else and i will work with the file.
but i must get to know if the file was copied completely before i work with it
|
|
|
|
|
If you try the following code
try{
System.IO.File.OpenWrite("MyFile.txt");
} catch (System.IO.IOException ex) {
System.Windows.Forms.MessageBox.Show("File is locked");
}
This will throw an error because the file is locked if it is still copying.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
Simple and to the point 'The Man from U.N.C.L.E.'
Thanks and Regards,
Aby
|
|
|
|
|
isn't there a possibility without throwing an exception?
|
|
|
|
|
Hey All,
I've been playing with the textbox in C#. I cannot seem to get it so that uppercase characters and lowercase characters take up the same amount of space in the box. For example like in the textbox here on CP to enter messages:
this line aligns perfectly with
THIS LINE ALIGNS PERFECTLY
They both align perfectly regardless of case. In my textbox, if I use uppercase on one line and lowercase on the next line, the uppercase line takes up a lot more space and they do not line up.
TIA!
|
|
|
|
|
...the two lines lign up perfect in the textbox here to enter in the message, but when it is displayed it is displaying exactly like I am talking about in my application.
|
|
|
|
|
Have you tried using a font like Lucida Console?
(Fixed width font - every character uses the same width)
|
|
|
|
|
Incredibly cool, that worked!!!! Thanks! Do you know how to tell (other than trying them one by one) which fonts are fixed width?
Again, thanks a lot!
|
|
|
|
|
You can retrieve a fixed width font family using System.Drawing.FontFamily family = System.Drawing.FontFamily.GenericMonospace.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|