|
Thanks again Judah.
It worked fine.
I really appreciate for your guidance.
I hope some day I can help you back.
See you
Free your mind...
|
|
|
|
|
hello,
i want to do the same thing using ""call by refernce method""....can anybody alter the code andf show to me the differnce please.... here i am using call by value i want to do this using call byt reference.....please the codes but the functionality should be the same so that it will be easy to understand,,,,thanks
class Program
{
public static int Add(int x, int y)
{
int result = a + b;
Console.WriteLine("{0}", result);
Console.ReadLine();
return 10;
}
static void Main(string[] args)
{
int sum = Add(10, 20);
Console.WriteLine("{0}", sum);
Console.ReadLine();
}
}
}
C#
|
|
|
|
|
How about
public static int Add(object x,object y)
{
int First;
int Second;
try
{
First = (int)x;
Second = (int)y;
return First + Second;
}
catch(Exception ex)
{
throw new Exception("Invalid values");
}
return 0;
}
|
|
|
|
|
hi,
thanks for trying to help....
but navneeth can you alter the previous program that will help me understand better....since i am not familiar with try catch and finally methods.....ie exceptions.....
i will be glad if you can alter the code and show to me that i have written...
thanks agin and expecting a reply
C#
|
|
|
|
|
That's not sending argument by reference, that's sending references as arguments.
---
"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
|
|
|
|
|
Guffa wrote: hat's not sending argument by reference, that's sending references as arguments.
Yes that was a mistake. I corrected that in second post
|
|
|
|
|
Why didn't you just edit the post?
---
"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
|
|
|
|
|
class Program
{
public static int Add(ref int x, ref int y)
{
int result = x + y;
Console.WriteLine("{0}", result);
Console.ReadLine();
return 10;
}
static void Main(string[] args)
{
int FirstNo = 10;
int SecondNo = 20;
int sum = Add(ref FirstNo ,ref SecondNo);
Console.WriteLine("{0}", sum);
Console.ReadLine();
}
}
Hope this helps
-- modified at 2:56 Friday 19th October, 2007
|
|
|
|
|
hi,
thanks a lot Navneeth ......your message realy helped.....i have altered the code a bit ......can you check and tell me whether my synatax is correct or not. i tried to run it and its running fine ....but i need your comment also....in the main function i made a slight alteration from yours.....plz check that and inform me
class Program
{
public static int Add(ref int x, ref int y)
{
int a = x; //saying that henceforth a will represent x
int b y ; //saying that henceforth b will represent y
int result = a + b;
Console.WriteLine("{0}", result);
return 10;
}
static void Main(string[] args)
{
int a = 10; //passing values to a and b
int b = 20;
int sum = Add(ref a,ref b);
Console.WriteLine("{0}", sum);
Console.ReadLine();
}
}
}
C#
|
|
|
|
|
kabutar wrote: return 10;
Why this return ? You have to return the result here. Remaining all looks fine. Hope you are cleared with call by reference and value concepts and how it works.
|
|
|
|
|
hi,
Navneeth what i was trying to do here is that i need the value of 10 to be returned...
ie we can say
return a;
the value assigned to a is 10...
so that value of a =10 will be returned ans stored inside sum so that we can use it for some other operation.....
am i correct Navneeth......??
also one more doubt in your code u have used a,b and first number and second number .what is the purpose of those.....
ie we have declred x and y as ref variables and are given refrence to a andf b.....
so what is the use of using firstnumber and secondnumber.....
please explain .....
thanks again for comming to my help
C#
|
|
|
|
|
kabutar wrote: also one more doubt in your code u have used a,b and first number and second number .what is the purpose of those.
It was a typing mistake. corrected now.
|
|
|
|
|
Thanks a lot ..........
cheers to you i understood something that i always had difficulty in understanding....
|
|
|
|
|
Welome.
|
|
|
|
|
Awesome work.....Navneeth.....
thanks a lot for helping me out....
thanks a million again
C#
|
|
|
|
|
You call by reference so you can change the parameters within the call. You sample has no benefit using references. A better example would be
public static void Add(int x, int y , ref int result)
{
result = x + y;
}
static void Main(string[] args)
{
int x = 5;
int y = 5;
int result = 0;
Add(x , y , ref result);
Console.WriteLine("{0}", result);
Console.ReadLine();
}
Here, the Add method has no internal members. It uses the pass by value x and y (by value so they can't change) to populate result , passed by reference so it can change. Within the Add signature, the parameters can be called different names....
public static void Add(int firstValue , int secondValue , ref int firstValueAddedToSecondValue)
{
firstValueAddedToSecondValue = firstValue + secondValue;
}
static void Main(string[] args)
{
int x = 5;
int y = 5;
int result = 0;
Add(x , y , ref result);
Console.WriteLine("{0}", result);
Console.ReadLine();
}
The advantage of this method, is you can then use a return value for success or failure of your Add function (if it becomes more complex)
public static bool Add(int x, int y, ref int result)
{
try
{
result = ReallyComplexCalculationDoneBy3rdPartyLib( x , y );
}
catch( Exception e )
{
return false;
}
return true;
}
static void Main(string[] args)
{
int x = 5;
int y = 5;
int result = 0;
bool AddWorked = Add(x , y , ref result);
if (AddWorked)
Console.WriteLine("{0}", result);
else
Console.WriteLine("Addition failed - check log file..etc");
Console.ReadLine();
}
Hope this helps.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Hi,
I have OpenOffice.org.Base in my machine, I am new to open office, But I am learing just.
I wanna know how to configure my C# application to OpenOffice's Database.
Thanks,
Prashanth
|
|
|
|
|
I am deploying my product using VSI. In that ther an option to do some action at Installation,Uninstallation. During the Uninstallation of my product i am calling an dll to do some task. There is an option to refere the dll in VSI. But it's asking me for an Entry Point, in my dll i mentiond a entry point as
static void main()
{
System.Diagnostics.Process.Start("NOTEPAD.EXE");
}
and i a, calling this main() as entry point.
After deploying the product, i installed the application and uninstall it for testing, tht dll is not calling/working for me.
Can any one suggest me an link/help how to solve this issue.
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
Exelioindia wrote: entry point for that dll.
Entry point of an application will be main() method. dll is a set of methods/classes. I don't think it needs an entry point.
|
|
|
|
|
hi,
if i have two classes animal(base class) and dog when do we use in the main statement: Animal a1 = new Dog();
because as i undersatnd we create the object of the same class and call methods of different classes after inheritance...ie is Dog a1 = new Dog().....
so how does this statement work:: Animal a1 = new Dog();
can anybody help me
thanks
C#
|
|
|
|
|
kabutar wrote: so how does this statement work:: Animal a1 = new Dog();
Why don't you write a program and experiment this ?
well, see the following code
class Animal
{
public virtual void ShowAnimal()
{
Console.WriteLine("From animal");
}
}
class Dog : Animal
{
public override void ShowAnimal()
{
Console.WriteLine("From dog");
}
}
I am initializing the class as you said
Animal a = new Dog();
a.ShowAnimal();
What will be the output ? This will print "From dog". Your object 'a' looks like Animal , but instantiated with Dog . So obviously it will call the overridden method in Dog class. Now remove the overide keyword in Dog class. It will be like
public void ShowAnimal()
{
Console.WriteLine("From dog");
}
Now run the application and you will find that it called base class function. Because the object looks like Animal , and instance don't have a method that has relation with Animal . Because child method with the same name without keyword oevrride will be considered as a new method. So it will execute base class method.
XMLDocument class having a Save() method which accepts a Stream object. Instead of this, we can pass MemoryStream object which is a child class of stream. So it will call MemoryStream classes methods.
Hope things are clear now. Let me know if it helped
|
|
|
|
|
hi,
thanks navneeth ......
letme conclude tis...
ie we use this method when we have to override am i right.......
hope my conclusion is correct....
thanking you Navneeth
C#
|
|
|
|
|
If you want to override the default functionality of the base class you can use this. If you are removing override keyword from child class, then use new keyword there to avoid compiler warning.
|
|
|
|
|
It also lets you store a collection of 'Animals' in a collection without having to have a collecton of dogs, a collection of cats, a collection of llamas, a collection of...I think you know where I am going.
You can just have a collection of Animals, and add any class dervied from Animal to it.
class Animal {};
class Cat : Animal {};
class Dog : Animal {};
List<Animal>_myListOfAnimals = new List<Animal>();
Animal myCat = new Cat();
Animal myDog = new Dog();
_myListOfAnimals.Add( myCat );
_myListOfAnimals.Add( myDog );
Saying this, if you are using inheritence just to have this ability, then interfaces are the way to go.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Hello,
I've spent some time trying to render text or even a control on top of video being played at fullscreen using the AudioVideoPlayback namespace without any luck.
Originally I was aiming to have a transparent control on top of the video, but if I can get text on top, or any control (transparent or not) I'd be happy...
Can someone point me in the right direction? Perhaps provide an example of something similar?
thank you,
khoramdin
|
|
|
|