|
i did 2 forms at Visual Studio 2008 in C#.
i want to save Number from the first form and to use it in another..
how can i create a Global variable?( that all forms have access to it.
for example:
int Num=3
i want that Form1 and Form2 will can change "Num".
|
|
|
|
|
global variables are poor design. try the singleton pattern instead, or better yet if you're using this as a parameter alone and not part of a class structure put it into a settings file and you'll have the parameter application wide.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
you can use the static or shared keyword depending on the language that you are using.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
how to call matlab command from c#? such as figure; plot
thanks.
|
|
|
|
|
I'm learning C# as part of my education and the hosting company where i work was nice enough to let me program automatic provisioning of sites and user, so i turned to the provisioning sample obtained on iis.net and adapting it and adding to it to make it work the way i want.
I'm creating it as a service as it makes it more manageable remotely. The thing is, im having a problem with quota control. When i add disk quota to a user it works fine but when i want to edit it or delete it, it doesn't work the way its supposed to. This problem only occurs when a user with the same name has previously been created and deleted. It seems like that when trying to i.e. edit the quota of the user, it actually edits the quota of the previous, deleted user. Hence a new quota entry is created which references to the SSID of the old, deleted user, not the current that it is supposed to use. This problem only occurs if the user is deleted by the service. If i delete the user (and folder, site, app pool and quota, as the service does) manually it works fine the next time a user is created with the same name.
I hope the above description makes sence. Anybody have any idea what goes wrong and how to fix it?
Thanks in advance.
I haven't lost 'till I'm the last one to cross the finishline.
|
|
|
|
|
I can convert a long using Convert.ToString(number, 2) but Convert.ToString(value, toBase) doesn't exist for ushort, uint, or ulong.
For Hex I use ulong.ToString("X") but I can't find a binary equivalent.
Dave
|
|
|
|
|
Hi,
the official names for the integer types are Int64, Int32, Int16, UInt64, etc.
So Convert.ToString() has what you need.
ms-help://MS.VSCC.v90/MS.msdnexpress.v90.en/fxref_mscorlib/html/0d16714f-b4f2-7157-b56d-b9b321ffa339.htm
|
|
|
|
|
The Convert.ToString() overloads for ulong/UInt64 and any of the other unsigned types only have (value, IFormatProvider provider) not (value, int toBase). The signed varieties do however.
Dave
|
|
|
|
|
There's probably a nicer way (and a .NET built in one), but this will also do the job:
static string UlongToString(ulong value)
{
int ulongsize = sizeof(ulong) * 8;
StringBuilder ret = new StringBuilder(ulongsize);
for (int i = 0; i < ulongsize; i++)
{
ret.Insert(0, value & 0x1);
value >>= 1;
}
return ret.ToString();
}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Cool! Thanks for that
I need to trimthe leading zeros (if any) now, but I should be able to figure that out.
Thanks again.
Dave
|
|
|
|
|
If anyone else comes accross this thread and wants to omit the leading zeros, insert if (value == 0) break; after the bit shift line.
Dave
|
|
|
|
|
You can omit the for loop (and thus the i counter variable) by changing the algorithm to
do
{
ret.Insert(0, value & 0x1);
value >>= 1;
}
while (value != 0);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Are you asking how to get the binary representation of the number?
i.e.
Int32 x = 15;
String s = x.ToString(""); and have s print "00000000000000000000000000001111"?
If that's the case, then you'll have to roll your own formatter, I remember looking a while back for something like this and came up with nothing. Doesn't mean it doesn't exist, I'm saying I had to write my own extension method to it.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
It's easy with Int32 but not UInt32 (or 16 or 64).
Post above works though. I'll have to look at CustomFormatters and learn something else new!
Thanks for your time.
Dave
|
|
|
|
|
Message Closed
modified 22-Jun-16 16:57pm.
|
|
|
|
|
Do you realise you posted to a 4.5 year old question?
|
|
|
|
|
I thought other people might like to know this.
|
|
|
|
|
No need to rant
By the way, you should use unchecked syntax to do it your way:
string binaryString = Convert.ToString(unchecked((long)ulong.MaxValue), 2);
|
|
|
|
|
how many times a word is used in a sentence,or its frequency
eg:
“this is a dog and that is a pig”
result:
“is”:2
“and”:1
th:2
is:3
i:4
thank you!
|
|
|
|
|
This should get you started.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace NeedsCode
{
class Program
{
static void Main(string[] args)
{
throw new NotImplementedException("CodeProject is not a free homework service.");
}
}
}
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
flowingsun wrote: how many times a word is used in a sentence,or its frequency
flowingsun wrote: “this is a dog and that is a pig”
result:
“is”:2
“and”:1
th:2
is:3
i:4
You answered your own question.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
No, that is not correct.
The result should be:
this: 1
is: 2
a: 2
dog: 1
and: 1
that: 1
pig: 1
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
There are three steps:
1. Write a function that goes through your sentence and isolates individual words.
2. For each word, check if it's in a hash table that maps strings to integers (counts). If it is, increment that word's integer and save it in the hash table's entry for that word. If it isn't, insert the word into the hash table with a one count.
3. Go through the hash table and print out each word and the integer associated with it.
You have to write the code yourself, though.
|
|
|
|
|
Hello everyone,
I am looking for some web service tutorials or code samples in depth, especially for the security/performance/scalability. Any reference?
thanks in advance,
George
|
|
|
|
|
google might help
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|