|
Does anybody know of a way to convert an INT to it binary representation?
i.e.
85 = 1010101
56 = 0111000
and so on
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Try checking out the System.Collections.BitArray class; it provides a pretty decent way of looking at/manipulating integers at the bit-level. I've used it a few times for win32 and mp3 stuff.
Also, if you only want to check the presence/abscence of a particular bit, use the '&' bitwise operator. I've found it's extremely worthwhile to truly understand the bit-level operators, especially if you're doing those type of operations frequently.
|
|
|
|
|
int intSomeNumber = 999;
string strBits = Convert.ToString( intSomeNumber, 2 );
Michael Flanakin
Web Log
|
|
|
|
|
Hey guys(first datagrid app and form app, be nice :p ), I am trying to bind a datatable to a datasource to a Datagrid and its not working...Im really confused. This is the compiler error I keep getting.
MyFormProject.MainForm.DataSource denotes a 'field' where a 'class' was expected.
-and-
MyFormProject.MainForm.DataGrid denotes a 'field' where a 'class' was expected.
the error line for 1st one is : ds.Tables.Add(dt);
the error line for 2nd one is : dg.SetDataBinding(ds,"Items");
ds is declared: private System.Data.DataSet ds;
dg is declared: private System.Windows.Forms.DataGrid dg;
Where this occurs:
public static void createset(database obj){
System.Data.DataTable dt = new DataTable("Items");
DataRow dr;
DataColumn dc;
int rowcount = obj.size;
System.Type typeint;
typeint = System.Type.GetType("System.Int32");
System.Type typestring;
typestring = System.Type.GetType("System.Int32");
dc = new DataColumn();
dc = new DataColumn("ID",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Name",typestring);
dt.Columns.Add(dc);
dc = new DataColumn("Type",typestring);
dt.Columns.Add(dc);
dc = new DataColumn("Buy Price",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Sell Price",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Weight",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Attack",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Defense",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Range",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Slot",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Gender",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Loc",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Weapon Level",typeint);
dt.Columns.Add(dc);
dc = new DataColumn("Player Level",typeint);
dt.Columns.Add(dc);
ds.Tables.Add(dt);
for(int i=0;i
|
|
|
|
|
Not sure how much help this will be but when I have needed to create datatables within code I tend to use the follow :
private void DataGen()
{
DataTable gridDt = new DataTable("grid table");
gridDt.Columns.Add("INT", System.Type.GetType("System.Int32"));
gridDt.Columns.Add("STRING", System.Type.GetType("System.String"));
gridDt.Columns.Add("LONG", System.Type.GetType("System.Double"));
for (int i=0; i<30; i++)
{
object[] rowData = new object[] { i, i.ToString(), DateTime.Now.Ticks };
gridDt.Rows.Add(rowData);
}
dataGrid1.DataSource = gridDt;
}
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Well I found the solution, and even tho it works perfectly I dont understand why it would not work before. All I changed was the dg.SetDataBinding thing by removing it and changing the return type from void to DataTable and then just saying that dg.DataSource = createset(database); Why does that make it work?!?! So confused.
|
|
|
|
|
I have several complex user controls built in separate C# projects that need a common interface. In the same solution is the container form where each control is attached. I've tried adding a class library project, with the needed interface, and adding the class library name to each of the projects references that need to inherit. The solution compiles but does not run. Any ideas?
Mel
|
|
|
|
|
Do you have an error message? If not, put a try/catch block around everything inside your Main() function, something like this:
public static void Main()
{
try
{
}
catch (Exception err)
{
System.Diagnostics.Trace.WriteLine(err.ToString());
MessageBox.Show(err.ToString());
}
}
Then, you'll have an error message that will help you diagnose the problem yourself.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
I've run into a problem with .NET remoting. I need the client to instantiate an object on the server, however, intantiating that object requires I pass parameters to the constructor.
public class MyObj
{
public MyObj(string s, long l, SR someReferenceType)
{
}
}
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyObj), "MyURI", WellKnownObjectMode.Singleton);
RemotingServices.Connect(typeof(MyObj), "http://localhost/MyURI");
The RemotingServices.Connect call throws an exception because there is no default constructor. I need to somehow pass several value types and a remote object reference type to the object being constructed (it'd even be ok if I passed this data to the object after construction, but that doesn't seem possible either).
Any ideas?
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
Create your own RealProxy derivative that can incercept the construction calls and instantiate your class with the parameters provided. Should work since you're now the one controlling how objects are created now.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the reply. I have now created a RealProxy derivative for my type. I've designed the RealProxy about as closesly as I could to some MSDN examples...is there anything else I need to do to make this work? I assume I've gotta hook up that proxy when I call .Connect to get the proxy on the client or similar, is that right?
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
You actually don't have to handle as much as you might think when creating your own proxy. You can choose to handle which methods you want. I recommend - if you haven't already - picking up a good book on .NET Remoting like "Microsoft .NET Remoting" from MS Press[^] or the one from Ingo Rammer[^] (supposed to be very good).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Look at the code: the are two similar methods. One declares all variables used in the method at the start of the method, the other one declares them when it needs then. May there be any lower CPU or memory cost in the second version of the method (the one at the bottom) ?
<br />
public void DoSomethingComplex(...)<br />
{<br />
int[] intarray = new ...<br />
bool somecondition = ...<br />
if (somecondition == true)<br />
intarray[1].Add ...
}<br />
<br />
public void DoSomethingComplex(...)<br />
{<br />
bool somecondition = ...<br />
if (somecondition == true)<br />
{<br />
int[] intarray = new ...<br />
intarray[1].Add ...
}<br />
}
Regards, Desmond
|
|
|
|
|
It's not really the declarations of things you have to worry about in general from a performance perspective; it's the allocation of things. Check this out:
<br />
using System;<br />
<br />
class Test {<br />
<br />
<br />
public static void DoSomethingComplex(bool _someCondition) {<br />
int[] intArray;<br />
<br />
if (_someCondition) {<br />
intArray = new int[100];<br />
}<br />
<br />
}<br />
<br />
static void Main(string[] args) {<br />
DateTime startTime, endTime;<br />
int millisecondCount;<br />
int loopCount = 100000;<br />
<br />
startTime = DateTime.Now;<br />
for(int x = 0; x < loopCount; x++) {<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
DoSomethingComplex(true);<br />
}<br />
endTime = DateTime.Now;<br />
millisecondCount = ((int)(endTime.Ticks - startTime.Ticks)) / 10000;<br />
Console.WriteLine(millisecondCount + " milliseconds" );<br />
<br />
startTime = DateTime.Now;<br />
for(int x = 0; x < loopCount; x++) {<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
DoSomethingComplex(false);<br />
}<br />
endTime = DateTime.Now;<br />
millisecondCount = ((int)(endTime.Ticks - startTime.Ticks)) / 10000;<br />
Console.WriteLine(millisecondCount + " milliseconds" );<br />
<br />
}<br />
}<br />
|
|
|
|
|
The second version is better since you allocate the memory only if
if (somecondition == true)
Howver you can do the following:
<br />
public void DoSomethingComplex(...)<br />
{<br />
int[] intarray;
bool somecondition = ...<br />
if (somecondition == true)<br />
intarray = new ...
intarray[1].Add ...<br />
}
|
|
|
|
|
Unless you are into really performance critical applications (and if you are, why aren't you using C++?) I think good coding style and design is generally more important than worrying about how questions like this.
I prefer to declare locals at the point where I going to use them, not detached at the head of the function. To me this localises the use of the variable, and is just better style. Anyway, we shouldn't try to second guess the compiler - for all we know, the compiled code is near identical in both cases.
|
|
|
|
|
Hi,
I would like to send data from one instantiation of class to a textbox in my Form.
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
.
.
}
public class AnotherClass
{
public void SomeMethod(String msg)
{
Form1.textBox1.Text = msg;
}
}
I have tryed setting the textBox1 public. I have try creating an accessor method. But no luck.
Any comments or suggestions would be very welcome.
Thanks in advance.
Jack
|
|
|
|
|
That isn't exactly proper programming practice. It could be done, but really, ALL your code for manipulating the controls on the form should be done on the form, not in a class that doesn't (shouldn't) know what a form is.
If all you doing is what it's your example, that code really shouldn't be in a seperate class. In order for it to work, you'd have to also pass a reference to the textbox to the SomeMethod function.
public void SomeMethod(ref TextBox tbToModify, String strMessage)
{
tbToModify.Text = strMessage;
}
RageInTheMachine9532
|
|
|
|
|
I want to write a application it like Microsoft's PowerPoint User interface..
when user add a new file my application can new a file but the file is adding to other form and can scroller to view and edit others file just like powerpint
how can i write the application or where has similar code...
please help me....thanks
|
|
|
|
|
You can add Microsoft PowerPoint Object Library to your project and use its powerpoint functionality. You can do it by add refrence-->CoM tab.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
sorry...i just want a interface like powerpoint which can satisfy my need.(can add a new file to a new form and can scroll up and down all forms just like powerpoint)
I do want't just use a powerpoint component....
everyone please help...thanks your ideas~~~
|
|
|
|
|
|
I am looking for a good book that explores .net diagnostics in depth such as topics about Tracing, Listeners, Event Logs etc. in .NET. Does anyone have any suggestions? I can't find any so far.
Mark Sanders
|
|
|
|
|
See the Microsoft Patterns and Practices[^] section. They have books available for download as PDFs (you can also buy them as books, but the PDFs are complete). One or two go into depth with instrumenting your application, like the Enterprise Instrumention block.
As far as trace listeners, the documentation for the TraceListener in the .NET Framework SDK should be sufficient. There isn't much you can do with these, though, which is where the EI comes into play.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have my multi-threaded plugin app that I wrote. In the dispose method of a plugin if I issue a Application.Exit it exits both the plugin and the parent app.
Is this normal, seems kinda strange to me...
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|