|
devidutta Pradhan wrote: Can anybody just guide me the difference
between these two declaration in c#
int a;
a=0;
and int a=0;
what is the diffrence is this anyproblem with performance issue??
As Luc pointed out, they are identical ways to do the same thing. There is no performance difference between either of them and both will get compiled to the same code.
However, your other example is different:
devidutta Pradhan wrote: classA a=new classA();
a=FunctionXXX();
classA a=FunctionXXX();
actually is somewhat ambiguous unless FunxtionXXX() returns a new instance of classA. If that is the case, then again, they are equivalent.
The different syntax exists mainly to support individual preference. Some developers prefer to always declare the variables and then assign them separately while others prefer to do it all in one step. In either case, the compiler doesn't care how it's done and treats these as the same thing.
|
|
|
|
|
|
The second one will create 2 objects, so it is less efficient.
This would be equivalent:
classA a;
a = FunctionXXX();
and
classA a = FunctionXXX();
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Hello, I'm new to both C# and sockets. I'm working on a program, that right now only read data from localhost and pass it directly over to a SOCKS-server on another computer.
Im running each connection in a separete thread. Problem is, I need to know when the client and server is done sending data. Right now it goes in a loop which takes up 100% CPU, not too good i guess. How can i tell when the communication is finished?
Also, since it takes up 100% CPU I guess its going through this loop loads of time over and over again, How can i read and write data better?
Appreciate any help or someone that could point me in the right direction.
while (true)
{
if (client.Available > 0)
{
l = client.Receive(lbuffer, 0, lbuffer.Length, 0);
remote.Send(lbuffer, 0, l, 0);
Console.WriteLine(l);
}
if (remote.Available > 0)
{
r = remote.Receive(rbuffer, 0, rbuffer.Length, 0);
client.Send(rbuffer, 0, r, 0);
Console.WriteLine(r);
}
}
|
|
|
|
|
Hello
I want to color my dataset row by row according to specialvariable in it
this my code:
1 private void Color()
2 {
3 for (int i = 0; i < this.dtgCreditInfo.Rows.Count; i++)
4 {
5 if (int.Parse(this.dtgCreditInfo.Rows[i].Cells["Status"].Value.ToString()) <= -1)
6 this.dtgCreditInfo.RowsDefaultCellStyle.BackColor = System.Drawing.Color.Red;
7 if (this.dtgCreditInfo.Rows[i].Cells["Status"].Value.ToString() == "1")
8 this.dtgCreditInfo.Rows[i].
9 //this.dtgCreditInfo.RowsDefaultCellStyle.BackColor = System.Drawing.Color.Aqua;
10 if (this.dtgCreditInfo.Rows[i].Cells["Status"].Value.ToString() == "0")
11 this.dtgCreditInfo.RowsDefaultCellStyle.BackColor = System.Drawing.Color.White;
12 }
13 }
The sixth line of code let whole the grid in the same color and also do the 11 line
so how can i solve this.
any help would be greatly appreciate
-- modified at 9:34 Sunday 28th October, 2007
Assaf
|
|
|
|
|
Instead of setting CellStyle for the whole grid, set it just for one row. Like this:
this.dtgCreditInfo.Rows[rowindex].DefaultCellStyle.BackColor = System.Drawing.Color.White
|
|
|
|
|
Thank you very much
Assaf
|
|
|
|
|
You are welcome
|
|
|
|
|
I have an DataSet with 2 tables. In one of the 2 TableAdapters are some methods I will use in an other method..So I made this code:
protected void Button1_Click1(object sender, EventArgs e)
{
PersoonTableAdapter data = new PersoonTableAdapter();
}
I will make an object of the tableadapter. It gives me an error abbout:
The type or namespace name 'PersoonTableAdapter' could not be found (are you missing a using directive or an assembly reference?)
I will add now a namespace like:
using rooster.DataSetRooster;
using rooster.app_code.DataSetRooster;
using PersoonTableAdapter;
But they all not work..
See here my dataset and my code:
picture 1
picture 2
|
|
|
|
|
khalidelmeknesi wrote: are you missing a using directive or an assembly reference?
Did you make a reference to the dll for the PersoonTableAdapter?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I dont understand your answer. How can I make an reference to the dll?
|
|
|
|
|
In the Solution Explorer window, there should be a node called References, add the .dll to that. You might have to right click on the Project/Solution name and choose Add Reference
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi,
I have an SDK written in C# which I would like to license out to other developers. Basically the SDK will check if the current machine running it has a license (this will be based on the machine key), if there is no license it will dislay a nag popup message, etc. However if an application has been built using this SDK on a licensed development machine, when the application is run (on any machine) the nag popup should not display (ie it will be royalty free). Is this at all possible to do using the .NET framework's licensing classes? If so can anyone suggest where I should start? Or if it is not possible, can anyone suggest some alternatives?
thanks
|
|
|
|
|
Having you tried searching Google? .NET does provide suport for a license file (.licx) that is usually used for UI components but I have seen it used for licensing other things as well.
|
|
|
|
|
You can also consider usage of 3rd party scheme like CryptoLicensing - it comes with built-in cryptographic LicenseProvider derived class for use with licx files.
|
|
|
|
|
Hi,
Here is what i want to do:
I want inside a panel display a graph (labeled xy-axis and some points in this graph connected with lines). I'm searching för a third party lib that can do most of the work for me.
I want to be able to label the axis and set the offsets myself.
I've googled a lot for my recent problem but haven't found an appropriate solution.
If there is anyone who knows of a a lib that i can set as a reference in the Visual studio 2005
i would greatly appreciate it!
Thanks
|
|
|
|
|
|
Hello!
I have an array of MemoryStreams. The main thread is updating one element at a time and the other threads are iterating over the array and checking if they are free to read the elements. If a MemoryStream is locked in the array, they won't read it and continue to another MemoryStream in the array.
How can I implement this scenario? I'm using the array as a buffer, the threads are reading from it and sending data over network, that's why I can't allow the main thread do the work of reading and sending the data. I need to make the other threads recognize and not read the element that is being updated.
Thank you
|
|
|
|
|
Hi,
szolDat wrote: I need to make the other threads recognize and not read the element that is being updated.
you could write a small wrapper around the stream to do this:
public class StreamLocker
{
private MemoryStream _stream;
private bool _isLocked;
public StreamLocker(MemoryStream stream)
{
_stream = stream;
_isLocked = false;
}
public MemoryStream LockStream()
{
lock (_stream)
{
if (_isLocked)
return null;
return _stream;
}
}
public void UnlockStream()
{
lock (_stream)
{
_isLocked = false;
}
}
}
Robert
|
|
|
|
|
Just my though.
However, there is two things wrong with your class.
First, you forgot to set _isLocked to true in the LockStream method.
Second, you should add an object to use for the locking. As the MemoryStream object is reachable outside the class, it could be used in a lock statement outside the class, which could cause a deadlock situation. Using a private object that isn't available outside the class prevents that.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Thank you for the answers.
What happens if a thread checks if a MemoryStream is available, sees that it is, and starts reading it, then the control is passed to the main thread. The main thread starts writing it, and if it gets to the point where the other thread is reading it, then that thread will return false data.
If I lock on a private object and not the MemoryStream itself, then how can I make sure that no one is reading that object?
|
|
|
|
|
szolDat wrote: What happens if a thread checks if a MemoryStream is available, sees that it is, and starts reading it, then the control is passed to the main thread. The main thread starts writing it, and if it gets to the point where the other thread is reading it, then that thread will return false data.
The main thread has to follow the same rules as the other threads, so that only one thread at a time has access to a specific memory stream.
szolDat wrote: If I lock on a private object and not the MemoryStream itself, then how can I make sure that no one is reading that object?
Using the lock statement on the memory stream doesn't protect the memory stream in any way. The object that is used in the lock statement is only used as an identifier, and the only thing that is protected is the code inside the lock statement block.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
"Using the lock statement on the memory stream doesn't protect the memory stream in any way. The object that is used in the lock statement is only used as an identifier, and the only thing that is protected is the code inside the lock statement block."
I think I get it. So the only way to restrict access is to force all threads to execute the same block of code for accessing the elements of the array, for example using the same accessor method or property? There isn't any way to lock objects in a memory, like you lock files with different reading / writing permissions? (I mean something like the System.IO.FileAccess.Read/Write/ReadWrite enum.)
|
|
|
|
|
szolDat wrote: So the only way to restrict access is to force all threads to execute the same block of code for accessing the elements of the array, for example using the same accessor method or property?
Yes.
Well, the crucial thing is the object that is used in the lock statement. There can be different blocks of code that access the array as long as they use the same object for locking.
szolDat wrote: There isn't any way to lock objects in a memory, like you lock files with different reading / writing permissions?
No.
Well, there is of course memory protection support in the processor, but that's on a completely different level.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Thank you for your kind help!
|
|
|
|