|
|
It will do what you tell it to.
When I use a Random I prefer to make one static instance that I use throughout the program.
private static readonly System.Random randy = new System.Random() ;
To get a random number in the range 1 -- 20:
int x = randy.Next ( 20 ) + 1 ;
|
|
|
|
|
|
Every day, you post questions that show you have no resources on C#, and are scared to use google. We love to help, but you're never going to learn to code unless you learn how to do basic research, and invest in at least one good book.
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 )
|
|
|
|
|
Trust me, I do invest in books, but it's not the same as a person telling you directly and so on, not that the site is the same either... The books are things that can't explain it to you if you don't understand what it says, though they usually do help.
|
|
|
|
|
Then use that book, to whack yourself on the head if for nothing else.
If you want to learn from a live person take a class.
|
|
|
|
|
PIEBALDconsult wrote: If you want to learn from a live person take a class.
Yep. Like the people in my class I teach
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
Well, I taught myself entirely from books, so my advice would be to grab a more basic book to start with. I sure did.
Contrary to what you may think, people here are not trying to take a shot at you, but it is frustrating to see so many people ask the most trivial questions, over and over, it really does make us wonder if anyone does any research at all. We want to help you, I'm giving you advice that I think is the best help I can offer.
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 )
|
|
|
|
|
Listen to what Christian has to say. He made it to MVP and started out by reading a couple of books. He's living proof that books do work.
|
|
|
|
|
The point they are trying to make is that if you goto Google and type "C# random", then you will quickly find what you need. In fact the first 5 (atleast) links explain how to generate a random number in C#.
The answers on those links may not be a quick and short C# snippet that you can directly cut and paste into your code. But I would expect any developer to research it, try some solutions, then if they can't get it to work then ask a question.
A large portion of doing software development is being able to do research, which includes searching the Internet and writing test code (that may never work and may get throw away).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I am not very proficient with VB6, but I am writing an ActiveX EXE for a legacy program to use.
I have code that receives data from the legacy software just fine (I can display it in a msgbox), but need an idea to push that data to a C# event to run some code based on the data.
I know how to hook into the ActiveX from C#, but am having trouble with the C# program recognizing that data is coming.
any help is appreciated and examples greatly appreciated.
-- modified at 19:48 Tuesday 2nd October, 2007
|
|
|
|
|
You can try with pass or return data the type of object not specific data type (int, string etc).
Parwej Ahamad
g.parwez@gmail.com
|
|
|
|
|
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!
|
|
|
|