TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Aditya Varma Mudunuri
NA
58
104.6k
dd inputs in runtime and add, print total using params key
Mar 17 2014 7:22 AM
Please Check the following code
Here I want to add inputs in runtime and add them and print total at the end using Params Keyword
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ParamsDemo
{
class DemoTest
{
public int Add(params int[] adds)
{
int sum = 0;
for (int i = 0; i < adds.Length; i++)
{
sum += adds[i];
}
return sum;
}
}
class Demo2
{
static void Main(string[] args)
{
DemoTest test = new DemoTest();
int size;
//In Static Method
/*
* int total = test.Add(25, 33, 88, 99, 44, 55);
Console.WriteLine("Result Obtained is "+total);*/
//In Dynamical Method
Console.WriteLine("Enter the No of Inputs to add");
size = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the {0} inputs",size);
for (int i = 0; i < size; i++)
{
Console.ReadLine();
}
int total = test.Add(size);
Console.WriteLine("Total Obtained "+total);
}
}
}
Reply
Answers (
1
)
Please check the code for splitting a string into 3 msgs
wcf in mvc ? help