|
By default, parameters are passed by value.
Click me[^]
|
|
|
|
|
Groan.. I know where you're coming from - for reference types, references to objects are passed by value by default. "Passed by reference" is not entirely accurate, but it describes the object sharing aspect well.
|
|
|
|
|
Depends on whether the parameter is a reference type or a value type?
|
|
|
|
|
By default, by value (a copy).
If the parameter is a value type, it's a "copy" of that value.
If the parameter is a reference type, it's a "copy" of that reference (by reference).
If you use ref or out:
If the parameter is a value type, you pass a reference (address) to it.
If the parameter is a reference type, you pass a reference to this original reference which refers to the object. As an example of this, write a function that takes 2 arrays and swaps them (without copying the elements).
Eslam Afifi
|
|
|
|
|
If reference(from stack) to the reference type(e.g object)is passed then, whatever changes done inside the functions are reflected to the object (as another copy of reference is created on stack which also point to original location e.g object)..........isn't it??
then what is the use of ref and out keyword here???
anybody like share??
|
|
|
|
|
class A
{
public Guid Guid;
public A()
{
Guid = Guid.NewGuid();
}
}
static void Main(string[] args)
{
var a = new A();
Console.WriteLine(a.Guid);
Foo(a);
Console.WriteLine(a.Guid);
}
static void Foo(A par)
{
Console.WriteLine(par.Guid);
par = new A();
Console.WriteLine(par.Guid);
}
static void Main(string[] args)
{
var a = new A();
Console.WriteLine(a.Guid);
Foo(ref a);
Console.WriteLine(a.Guid);
}
static void Foo(ref A par)
{
Console.WriteLine(par.Guid);
par = new A();
Console.WriteLine(par.Guid);
}
Eslam Afifi
modified on Thursday, March 19, 2009 10:48 AM
|
|
|
|
|
deep@Pune wrote: then what is the use of ref and out keyword here???
ref and out pass the reference to the reference by value
|
|
|
|
|
Hello. I'm developing a Windows Mobille App, and i cannot allow users to leave the application, by clicking in start menu or side/down buttons. Can anyone help, please?
Thank you.
|
|
|
|
|
I'm developing a new steering-wheel, and I don't want you to use your brakes while you're in your car.
That didn't sound very nice, did it?
I are troll
|
|
|
|
|
My apologies for the rude comment. It's not nice to hijack someone's phone. Then again, that's no good reason for me to get rude.
Why do you need to prevent an exit? It might be a design-problem, or a requirement, but that doesn't mean that there's no (good) alternatives
I are troll
|
|
|
|
|
(sorry for the poor english)
it's an application for policemen, fine cars and things like that. i want to block the ppc so they just use the ppc for my app.
|
|
|
|
|
it's ok , i did not express myself well. i don't wanna screw anyone's phone. just making sure they just use it for theirs jobs, not going online with IE or listen to music, got it?
|
|
|
|
|
Got it a lot better than a few minutes ago
Some of the special keys are actually sent to the application, but this varies from phone to phone, since there's no standard defined. If memory serves correct, the iPaq sent the four keys on the front (under the touchscreen) as cursor-keys.
This may prove easy or very hard, depending on your phone. I'm sorry that I couldn't help you any further.
I are troll
|
|
|
|
|
What if you log every time they leave your app and send non-empty logs to HQ every 24 hours or so? Then they Can use it for something else if they Have to (for some reason) but they'd have to explain why it was necessary since HQ knows about it
If that's allowed..
Sounds like a more reasonable solution to me, but hey I'm not a police officer or their superior
|
|
|
|
|
i like this idea, don't think they'll like too. well, i'll try some things here. thank you all
|
|
|
|
|
arimao wrote: cannot allow users to leave the application
Why?
Think about it, what if something unexpected happens on the device that causes your program to crash? Now the user is holding a brick unless they restart it, but I guess you're gonna want to make your app auto run on start up (pointless blocking them otherwise), so they've now got a permanent brick - unless they reset it and loose all their data along with your application. They'll be happy they've got rid of your app but angry as hell about their data loss.
So, I ask again - why?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I have created a windows service that runs a timer which checks the time on the local computer, and at a certain time, it will call a webservice I have created. It runs beautifully on the computer that I developed it on, but when I try to install and run it on a different computer, it stops immediately with the error message
"The service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs."
I am not sure if it is a rights thing, or if I am missing something when I created the installer and setup files.
The windows service is written in C#, and so is the web service it calls. It also writes to the event log, and i am not sure it that would have an affect.
Things I have tried:
1. created a setup project in Visual Studio to install the service.
2. moved the project to the remote computer to build it and try to install it using the installutil program.
3. tried another computer in addition to the first remote computer
I know it is possible, and I am sure I am just missing something. Any help would be greatly appreciated.
Thanks,
heather
|
|
|
|
|
Hi
I suggest to install the service manually
in order to understand if the problem cause by the installation program
|
|
|
|
|
Your service is written incorrectly. It sounds like you started a Timer in the OnStart handler to run the service. The is not a good idea. Normally, services are expected to start a seperate thread that runs code that does the service work.
|
|
|
|
|
Hello Dave. Thank you for the information. I am new to this, and this is the first time I have written a windows service. I have a function that initializes the timer, and I have it set to run in the Onstart handler of the service. I put it in the service so it would start back even if the computer rebooted unexpectedly. How can I modify it to start a separate thread? I am not very familiar with threads yet either.
Thanks again,
Heather
|
|
|
|
|
Hi!
I want to rewrite one of my fameworks from php to c# so i can use them to play with asp.net.
So my question is:
since i have a file for the databasehandler class and one for the date and time class and so on,
i wonder if i could do like in php and have one file that includes or at least gives access to the other classes?
So that when i want to use my framewok i only have to work with one file and not all the 20 different files.
/Arne
|
|
|
|
|
Yep, you can create a single dll that contains all your classes, but you may want to consider splitting them out for maintainability/readability.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
ah, tink you got me wrong there.
i want to have something like this "file three"
this is how my php setup work's
EleanorFramework/(my framework's name)
___Eleanor.php(here i include all my file's in the Classes folder)
___Classes/
______Databasehandler.php
______Textapi.php
______logger.php
______...
so when i want to use my framework in php i include Eleanor.php
and creates the class i want to use.
and i wanna do something like that in my class library.
/Arne
|
|
|
|
|
Yeah you can.
Create seperate class library projects
Eleanor.Databasehandler
Eleanor.Textapi
etc... and reference the output dlls of the sub projects in an Eleanor project.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
If this is for a web site, when you add classes to a .Net web app, it puts them into a special folder (AppData or something like that). You can assign a namespace to each class if you like (but it's not necessary), and then include a using statement so that you can access the class inside that namespace. Personally, I find that a bit clunky.
If you want to be able to share the classes between projects, you can create a separate solution that contains these classes and then simply add a reference to it in any web site from which you might want to use them.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|