|
Well, it's plainly not 1 or 3. I'm not sure what 4 means, but I doubt it's that. It must be 2, although I have no idea what that means, either.
Reflection allows you to look at private variables, I believe. But, a type safe variable just means a variable that is typed. A variable is just
int x;
that has no features at all, it's just a variable. So, I assume they mean a property, not a variable. The question itself is retarded, IMO.
If it's a property, then you can do this:
int x
{
get
{
return myPrivateInt;
}
}
but, type safety has nothing to do with it, this would work if x was of type object. And, if this is called 'code access control', that's not a term I've ever heard.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
Zealous_Me wrote: Which feature of a type safe variable allows the variable to access a value from the private field of an object ?
Zealous_Me wrote: 2.) Code access control
I agree with Christian - The question is CAC
|
|
|
|
|
Hello experts,
I've written a producer/consumer class which I will be using in my current project.
Here's a snippet of my class:
private Queue<NextDataReply> packs;
private bool productionDone;
private void Enqueue(NextDataReply pack)
{
lock (packs)
{
packs.Enqueue(pack);
Monitor.PulseAll(packs);
}
}
public NextDataReply Dequeue()
{
lock (packs)
{
while (packs.Count == 0 && !productionDone)
Monitor.Wait(packs);
if (productionDone) return null;
return packs.Dequeue();
}
} AFAIK, this is the accepted and prefered way to go about synchronizing queue access.
However, I can't figure out something...
Consider the following scenario:
The consumer has called Dequeue() , and is now blocking on Monitor.Wait() , waiting for data to be added to the queue.
The producer has now called Enqueue() and has reached the lock statement.
Isn't this a deadlock situation?
The way I see it, the consumer has aquired the lock for the packs object, and calls to lock would block until the consumer has exited the critical section of Dequeue() (which never happens, as it is blocking on Wait() ).
Explain it to me please...
|
|
|
|
|
Wait() actually "toggles" the lock, so the other thread can enter the lock while Wait is running. After receiving the Pulse, Wait re-acquires the lock.
|
|
|
|
|
shyagam wrote: Isn't this a deadlock situation?
No. If you read the documentation for Monitor.Wait , you'll see that it blocks the calling thread after releasing the lock. When some other thread pulses the lock, the blocked thread reacquires the lock. If it didn't, then it would be useless, as Wait can only be called after acquiring a lock and no other thread will be able to acquire the lock to release/wait on it.
|
|
|
|
|
I see... Now it makes sense.
Thank you both!
Regards,
Shy.
|
|
|
|
|
I want to create my own collection of elements. I do it so:
public class MyCollectionName : IEnumerable
{
List<string> m_Collection = new List<string>();
public int Count
{
get { return m_Collection.Count; }
}
public IEnumerator GetEnumerator()
{
return m_Collection.GetEnumerator();
}
}
Is it possible to use instance of MyCollectionName like array and
what should I change in MyCollectionName class for it?
for example:
for(int i = 0; i < myCollectionInstance.Count; i++)
{
myCollectionInstance[i];
}
|
|
|
|
|
yes, thats called an indexer; it is like a property that takes an integer argument.
Example:
public Record this[int index] {
get {return (Record)currentRecords[index];}
}
gives the containing class a getter that returns an item of type Record.
|
|
|
|
|
Add a default indexer:
public string this[int index] {
get { return m_Collection[index]; }
}
---
single minded; short sighted; long gone;
|
|
|
|
|
|
Hi All
I want to link the data result set from the database, to a DataGrid. I want to display it other than just columns as it comes from the database.
ie. The usual DataGrid format
------------------------------------------------------
Column Data | Column Data | Column Data | Column Data
------------------------------------------------------
I want to display like this:
-------------------------------
Column Data |
------------|
Column Data | Column Data
------------|
Column Data |
-------------------------------
Hope that makes sense.
Thanks in advance.
|
|
|
|
|
|
We don't do other peoples exams here.
---
single minded; short sighted; long gone;
|
|
|
|
|
if you don't have a clue to the answer then just keep your ugly ass out of here and if yiu know the answer reply it to the question.
|
|
|
|
|
Zealous_Me wrote: if you don't have a clue to the answer
That is not the point.
I choose not to answer your question because it's clearly taken from a test, and I won't help you cheat.
Zealous_Me wrote: then just keep your ugly ass out of here
Unless you have actually seen my ass, don't pass judgement on it's ugliness. Also the whereabouts of my ass is hardly any of your business.
---
single minded; short sighted; long gone;
|
|
|
|
|
|
Agreed, but if he's asking it here, I presume the exam is over. ( FWIW, he asked again, and I didn't spot the double post, and answered, on the basis that I thought the exam was over, and it was a postmortem ). Could you make sense of the question ? Am I just stupid ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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've seen too many take-home tests to take that chance. If he would have put what he thought about the answers, then I probably would have chimmed in.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Take home tests, in the day of google ? That's bizarre.
If the question made sense and was straitforward, I probably would not have replied. But, the question seemed stupid, so I understood why there would be confusion surrounding it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
Christian Graus wrote: Take home tests, in the day of google ? That's bizarre.
They still have to teach these kid who to type "www.google.com". It seems to be a lesson that's missing from so many ciriculums.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Christian Graus wrote: Could you make sense of the question ?
Not really. A variable doesn't access values at all, so the question truly makes no sense.
---
single minded; short sighted; long gone;
|
|
|
|
|
|
How can i make a file that you can only go into by entering a password? like when you put a password on your conversations in messenger plus you need to enter a password to go in, how can i do something like that?
|
|
|
|
|
You can apply ACL ( Access control list ) to files through .Net.
Try this[^] link
Here is another one[^]
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
I was trying to debug a dll I made in C# using Visual Studio .NET 2003. I want to be able to walk through the code and use breakpoints and so...
I tried using the debug options and I set the debug action to start the program that uses the dll.
The program started but it never stopped at the breakpoints.
Then I tried to use a MessageBox where I want to set a breakpoint and the program showed the message correctly.
I tried to attach to the process in which the host program runs but it failed with the "failed to attach to process" message.
Any answers?
|
|
|
|