|
what is the difference between int? and int
seema
|
|
|
|
|
The question mark denotes it is a nullable value. For example,
int? i = null;
is the same as
Nullable<int> i = null;
The Nullable<T> type wraps a value type, like integers, but allows you to assign null to them. Without this, you couldn't assign null to an int or any other value type.
|
|
|
|
|
int? is shorthand for INullable<int>
A nullable type can be null as well as the normal values and has a HasValue property. Very useful, for example, if you have a numeric column in your database which can be null, or just in general to avoid having to have magic numbers to indicate that no value has been set.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi there, i want to know how to setup to nhibernate for use the SysCache2 in my AspNet 2.0 Application... this is what i have been doing, in the web.config:
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration>
<session-factory xmlns="urn:nhibernate-configuration-2.2">
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">server=XXXX;database=XXXX;uid=XXXX;password=XXXX;Max Pool Size=100;Enlist=False</property>
<property name="cache.use_query_cache">true</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache2.SysCacheProvider,NHibernate.Caches.SysCache2</property>
<mapping assembly="Model" />
</session-factory>
</hibernate-configuration>
And in my class i do the following:
public static IList<Country> GetCountryList()
{
string sql = "from Model.Country c Order By c.Countryid";
IQuery query = Base.Session().CreateQuery(sql);
query.SetCacheable(true).SetCacheRegion("nhibernate.country.countrylist");
IDictionaryEnumerator e = HttpContext.Current.Cache.GetEnumerator();
while (e.MoveNext())
{
//The first time nothing happen here
//After that the System.Web.HttpContext.Current.Cache.Count is 2
//How can i get the cached collection??
object o = e.Current;
object k = e.Key;
object v = e.Value;
}
return query.List<Country>();
}
Any help would be appreciated.
Bye.
p.d:oops, its the c# forum, my code was in vb net, now is in the right language
-- modified at 18:32 Tuesday 2nd October, 2007
|
|
|
|
|
I'm having trouble deserilizing an xml node that has empty tags. See
XML:
<ContentCampaign>
<ad_id_source type="integer"></ad_id_source>
<billing_code type="integer"></billing_code>
<birth type="datetime">2007-08-24T16:15:16-07:00</birth>
<body>this campaign has alerady been sent</body>
<category_id type="integer">1</category_id>
<created_at type="datetime"></created_at>
<id type="integer">4</id>
<name>complete_campaign</name>
<notes></notes>
<subject>this campaign is read to send</subject>
<thumbnail></thumbnail>
<updated_at type="datetime"></updated_at>
<valid_after type="datetime"></valid_after>
</ContentCampaign>
This XML is generated from a rails web service and respresents a table
in the database.
When I try to deserilize this the deserlizer fails on the empty tags.
How can I make the deserializer simply ignore these tags as they have
no value anyways...?
/\ |_ E X E GG
|
|
|
|
|
Check out this[^] for elements and this[^] for attributes. Basically, you are going to read them in, but you can trash them later.
Or you could use this[^] to ignore those elements/attributes.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Sorry, But I'm a little overwhelmed. Maybe you can help me more if I'm more specific.
I have this XML that I'm trying to serilize into a ContentCampaign obj.:
<ContentCampaign xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<id>0</id>
<name>serilizatoin test</name>
<category_id>4</category_id>
<subject>i am subject</subject>
<body>i am body</body>
<birth>0001-01-01T00:00:00</birth>
<ad_id_source>4</ad_id_source>
<valid_after>0001-01-01</valid_after>
<billing_code>0</billing_code>
<created_at>0001-01-01T00:00:00</created_at>
<updated_at>0001-01-01T00:00:00</updated_at>
<notes></notes>
</ContentCampaign>
It works find until a field node is empty. For example <code><ad_id_source></ad_id_source></code>. This xml is generated from a database table and when a value is null it simple generates an empty xml node.
The problem with the empty ad_id_source node is tha now, when the deserializer runs, it throws an exception.
Simply, is there a way for the deserializer to ignore these empty nodes?
I noticed that if a node that maps to a string is empty is just defaults to null. Can I configure the deserilizer to set any empty nodes respective type to it's default value? eg. 0 for int, 0001-01-01 for DateTimes?
-- modified at 19:59 Tuesday 2nd October, 2007
/\ |_ E X E GG
|
|
|
|
|
I'm sorry, I misunderstand what you wanted. I though you had extraneous elements (e.g. items without a matching property in your C# class) that you wanted to skip.
You could derive your own class from XmlTextReader[^]and override the Read[^] method. But that would get messy because you have to take into account elements that only have sub-elements.
The easiest way is to probably define another property that you use for serialization like so:
private Int32 myInt = 0;
[XmlIgnore]
public Int32 MyInt {
get {
return this.myInt;
}
set {
this.myInt = value;
}
}
[XmlElement("MyInt")]
public String MyIntSerialize {
get {
return this.MyInt.ToString();
}
set {
Int32 newValue = 42;
if (!String.IsNullOrEmpty(value))
newValue = Int32.Parse(value);
this.myInt = newValue;
}
}
This gets messy also because you have to double up on your properties.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi,
I've just decided to impliment a support layer that removes empty nodes. This is working now and I haven't found any issues with it:
string ct = this.HttpWebResponse.Headers["Content-Type"];
if (ct.Contains("application/xml"))
this.response_text = FilterOutEmptyNodes(this.response_text);
}
private string FilterOutEmptyNodes(string p)
{
return System.Text.RegularExpressions.Regex.Replace(p, "<[^>]*><[^>]*>", "");
}
/\ |_ E X E GG
|
|
|
|
|
I asked this question before, but I lost the forum post, so here it is again. How do you make a label (or status-strip) count up in seconds from a timer? It's really simple, but not cming to me right now. Thanks in advance...
|
|
|
|
|
In the timer code that fires each time you have a tick ( assuming you set it to one second), you get the value from your label's text, increment it by 1.
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
That's what I need. It's something close to (x++) or something...
|
|
|
|
|
Oh, I just got it. Thanks for even trying to help!
|
|
|
|
|
MasterSharp wrote: Oh, I just got it. Thanks for even trying to help!
No problem at all.
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
One suggestion. Timers are not perfect, so I'd get the time from DateTime.Now and show a difference, if you want it to be perfect. I'd also update twice a second, so it doesn't ever skip a number.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I don't understand how to set an Icon. After you add the icon file to the solution explorer, and set it to the form, the icon always makes a page picture, not the icon I chose. Please help, thanks in advance!
|
|
|
|
|
You could:
A) add the icon as a resource and retrieve it and set it programatically
or
B) rename your icon file to App.ico and drop it into your solution's folder
B is the quick and dirty way of doing it
---
http://iheartdotnet.blogspot.com/
|
|
|
|
|
i want to make a programe to convert numbers to alphapitic with c#
example:
1200 when it convert ,it will be
one thousand and two hundreds
|
|
|
|
|
see here[^] and here.[^]
--
If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
|
|
|
|
|
|
This is a very easy and standard homework problem. Do it yourself!
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
i think it is your class assignment .............
I AM WORKING ON "PLOTTER ROBOT"(FYP).
|
|
|
|
|
memaia wrote: i want to make a programe to convert numbers to alphapitic with c#
Permission granted. Please, proceed.
|
|
|
|
|
You should email his teacher
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
"There is a program that does that very thing right here on code project already.
http://www.codeproject.com/cs/design/TestFirstDevelopment.asp[^]
Remember: Google is your friend. "
Gosh Colin - how ever did you come up with that link so quickly? And how come you didn't comment on his use of such a rubbish post title?
Deja View - the feeling that you've seen this post before.
|
|
|
|