Click here to Skip to main content
15,925,181 members
Home / Discussions / C#
   

C#

 
AnswerRe: c# unique character in char array Pin
#realJSOP14-May-18 6:43
professional#realJSOP14-May-18 6:43 
GeneralRe: c# unique character in char array Pin
Mycroft Holmes14-May-18 14:13
professionalMycroft Holmes14-May-18 14:13 
GeneralRe: c# unique character in char array Pin
#realJSOP15-May-18 3:46
professional#realJSOP15-May-18 3:46 
QuestionWinforms - Find Value in Collection Containing Instantiations of a Custom Class Pin
DabbingTree11-May-18 8:37
DabbingTree11-May-18 8:37 
AnswerRe: Winforms - Find Value in Collection Containing Instantiations of a Custom Class Pin
Richard Deeming11-May-18 9:04
mveRichard Deeming11-May-18 9:04 
AnswerRe: Winforms - Find Value in Collection Containing Instantiations of a Custom Class Pin
BillWoodruff11-May-18 23:43
professionalBillWoodruff11-May-18 23:43 
QuestioniTextSharp - Character problem Pin
User 1367511411-May-18 1:10
User 1367511411-May-18 1:10 
AnswerRe: iTextSharp - Character problem Pin
Luc Pattyn13-May-18 23:18
sitebuilderLuc Pattyn13-May-18 23:18 
QuestionA second form from the first form, but both are active Pin
trottl10-May-18 23:18
trottl10-May-18 23:18 
AnswerRe: A second form from the first form, but both are active Pin
OriginalGriff10-May-18 23:25
mveOriginalGriff10-May-18 23:25 
GeneralRe: A second form from the first form, but both are active Pin
trottl10-May-18 23:32
trottl10-May-18 23:32 
GeneralRe: A second form from the first form, but both are active Pin
OriginalGriff10-May-18 23:47
mveOriginalGriff10-May-18 23:47 
AnswerRe: A second form from the first form, but both are active Pin
BillWoodruff12-May-18 0:00
professionalBillWoodruff12-May-18 0:00 
QuestionMultiple clicks on one button scrolls through selection choices Pin
Member 1382104810-May-18 5:19
Member 1382104810-May-18 5:19 
SuggestionRe: Multiple clicks on one button scrolls through selection choices Pin
Richard Deeming10-May-18 5:55
mveRichard Deeming10-May-18 5:55 
AnswerRe: Multiple clicks on one button scrolls through selection choices Pin
OriginalGriff10-May-18 6:06
mveOriginalGriff10-May-18 6:06 
GeneralRe: Multiple clicks on one button scrolls through selection choices Pin
Luc Pattyn10-May-18 6:24
sitebuilderLuc Pattyn10-May-18 6:24 
GeneralRe: Multiple clicks on one button scrolls through selection choices Pin
OriginalGriff10-May-18 6:44
mveOriginalGriff10-May-18 6:44 
GeneralRe: Multiple clicks on one button scrolls through selection choices Pin
Luc Pattyn10-May-18 6:55
sitebuilderLuc Pattyn10-May-18 6:55 
GeneralRe: Multiple clicks on one button scrolls through selection choices Pin
OriginalGriff10-May-18 7:59
mveOriginalGriff10-May-18 7:59 
AnswerRe: Multiple clicks on one button scrolls through selection choices Pin
BillWoodruff10-May-18 10:56
professionalBillWoodruff10-May-18 10:56 
AnswerRe: Multiple clicks on one button scrolls through selection choices Pin
Pete O'Hanlon10-May-18 21:45
mvePete O'Hanlon10-May-18 21:45 
Questionc# while loop Pin
swathiii8-May-18 23:04
swathiii8-May-18 23:04 
AnswerRe: c# while loop Pin
OriginalGriff8-May-18 23:37
mveOriginalGriff8-May-18 23:37 
That won't compile. Why not? You don't declare tem2, and if you do, you need to give it a default value or you can't return it.
In addition there is no good reason for a local function here: it just makes the code harder to read.

If it doesn't compile, it doesn;t generate an executable file, so the version you run is the last "compile error free" version of your source code.
Fix the compilation errors, and it may work better:
public static void Main(string[] args)
    {

    int ip1, ip2, ip3, ip4, res, tem2 = 0;
    ip1 = Int32.Parse(Console.ReadLine());
    ip2 = Int32.Parse(Console.ReadLine());
    ip3 = Int32.Parse(Console.ReadLine());
    ip4 = Int32.Parse(Console.ReadLine());
    res = summeet(ip1, ip2, ip3, ip4);
    Console.WriteLine(res);
    }
private static int summeet(int p1, int p2, int p3, int p4)
    {
    int a, b, c, n, tem1, tem2 = 0, i = 0, d1, d2;
    a = p1;
    b = p2;
    c = p3;
    n = p4;
    while (i > n - 3)
        {
        d1 = b - a;
        tem1 = d1 + c;
        d2 = c - b;
        tem2 = tem1 + d2;
        i++;
        tem1 = tem2;
        }
    return tem2;
    }
But do yourself a favour: stop using as-short-as-possible names for things: it may seem like a waste of time and more work, but using descriptive names makes your code document itself, and that means it's more readable. It also means it's a lot easier to tell when you used the wrong variable, and that makes your code more reliable and easier to debug. the variables a, b, c, and n are unnecessary, you can use the parameters directly instead; and give them sensible names instead of "p1", "p2" and so on. That way, when you want to use the method later, Visual Studio will even prompt you as to what value belongs in what parameter!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

AnswerRe: c# while loop Pin
Pete O'Hanlon9-May-18 1:32
mvePete O'Hanlon9-May-18 1:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.