|
There are a few ways of obtaining multiple values.
1. Create an struct/class that holds more than one value
2. Use an array or list (the same as 1 really)
3. Use an out (or ref if needed) parameter.
1:
public class Pair<T>
{
private T first;
private T second;
public Pair(T first, T second)
{
this.first = first;
this.second = second;
}
public T First { get { return first; } }
public T Second { get { return second; } }
}
public static Double Test(Double Val1, Double Val2, Double Val3)
{
Double Test_Val = Val1 + Val2 + Val3;
Double Second_Test = Test_Val % 2;
return new Pair<Double>(Test_Val, Second_Test);
}
2 should be straight forward.
3:
public static Double Test(Double Val1, Double Val2, Double Val3, out Double secondResult)
{
Double Test_Val = Val1 + Val2 + Val3;
secondResult = Test_Val % 2;
return Test_Val;
}
|
|
|
|
|
out and ref parameters are usually considered to be dirty, so stay away from that if you can.
Depending on what the function does, you may want to create a wrapper class or struct for the result. That means that you get semantically useful names, instead of First and Second from the Pair class.
|
|
|
|
|
Also, he could return a Tuple<type,type> but by far the best is solution 1.
|
|
|
|
|
Use ref and out keyword to return multiple values from function
return statement returns only single value.
|
|
|
|
|
the quick and dirty way:
public static Double[] Test(Double Val1, Double Val2, Double Val3)
{
Double Test_Val = Val1 + Val2 + Val3;
Double Second_Test = Test_Val % 2;
double [] arr = { Test_Val, Second_Test };
return arr;
}
Just to show you, you can return virtually anything, including Lists, Dictionaries, self made object (like the Pair example)
V.
|
|
|
|
|
|
Please am working on an application that use datagrid view but am looking for tutorial or code that i can use to insert,update record that i retrieved from the database.
|
|
|
|
|
|
Don't use short URL's. People have no idea where that URL is actually going.
|
|
|
|
|
|
I wanna know, is it possible to read windows 7 User account password from the windows registry?
|
|
|
|
|
A Reset Tool downloaded here[^].
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I want to know can we write a piece of code in c# that gets it from registry or not?
even is the windows password saved in registry or not?
|
|
|
|
|
No.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
Kuthuparakkal wrote: Since a hash function is one-way, this provides some measure of security for the storage of the passwords.
..which means you can read the hash, but not the password.
Kuthuparakkal wrote: Boot with some instant (DVD) os and read it.
..and end up with useless data; it's not possible to get the key, decrypt the hash and find the matching password. You could wipe out the entire section with a tool, but that's about it.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
No hacker has the required resources.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
No, there are people out there who know how to get the hashes. After that, you have to brute-force dictionary attack the hashes to get the passwords which can take a considerable amount of time.
|
|
|
|
|
Not yet, as far as I know. At least, not if the password isn't short (or findable by a dictionary attack).
On XP and previous, it was trivial to crack that nice LM hash, but Vista+ doesn't store the LM hash anymore.
|
|
|
|
|
<pre lang="c#"></pre>Error 1 An object reference is required for the non-static field, method, or property 'ConsoleApplication_FileTest.Program.GetAverageSalary(string)' C:\Users\Dawn\documents\visual studio 11\Projects\ConsoleApplication_FileTest\ConsoleApplication_FileTest\Program.cs 98 24 ConsoleApplication_FileTest
<pre lang="c#"><pre>static void Main(string[] args)
{
Dictionary<string, double> averages = new Dictionary<string, double>();
string filename = "c:\\test.txt";
averages = GetAverageSalary(filename)
} </pre></pre>
=====================
<pre lang="c#"> Dictionary<string, double> GetAverageSalary(string filename)
{
... </pre>
|
|
|
|
|
Your method main() is static.
Your method GetAverageSalary() is not. So it MUST have an object instance of type Program.
But I suspect you might solve it by making GetAverageSalary() static. However that depends on what you are trying to learn.
|
|
|
|
|
How do I mae an object instance of type Program?
|
|
|
|
|
Xarzu wrote: type Program
Program prg = new Program();
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
..that's why I usually change it to a static class altogether.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|