.Net interview questions asked in capgemini


You should be familiar with this question also before going to any interview 

How to sort numbers in c#

For example I want to sort these given numbers 40,85,69,125,1,83,5,895,1000

C# syntax :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace SortingNumbers

{

class Program

{

static void Main(string[] args)

{

int[] array = {40,85,69,125,1,83,5,895,1000};

array = (from a in array orderby a ascending select a).ToArray();

foreach (int i in array)

{

Console.WriteLine(i);

Console.ReadLine();

}

}

}

}

How to reverse sting value in c#

C# program to reverse as string using for loop

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

string Str, Revstr = “”;

Console.Write(“Enter A String : “);

Str = Console.ReadLine();

for (int i = Str.Length – 1; i >= 0; i–)

{

Revstr = Revstr + Str[i];

}

Console.WriteLine(“Reverse  String  Is  {0}”, Revstr);

Console.ReadLine();

}

}

} 

OUTPUT :

Enter a string : RAJESH

Reverse  String  Is : HSEJAR

How to Print Even numbers:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine(“Please enter your target”);

int targetNumber = 0;

targetNumber = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i <= targetNumber; i = i + 2)

{

Console.WriteLine(i);

}

Console.ReadLine();

}

}

}

 OUTPUT:

Please enter your target = 5

0

2

4

Similarly Print ODD Numbers:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine(“Please enter your target”);

int targetNumber = 0;

targetNumber = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i <= targetNumber; i = i + 3)

{

Console.WriteLine(i);

}

Console.ReadLine();

}

}

}

Increment a numerical string

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

string s = “12345”;

s = (int.Parse(s) + 1).ToString();

Console.WriteLine(s);

Console.ReadLine();

}

}

}

OUTPUT

12345

12346 

Increasing an Array :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Increase_Array

{

public class Routine

{

public static void IncreaseArray(ref string[] values, int increment)

{

string[] array = new string[values.Length + increment];

values.CopyTo(array, 0);

values = array;

}

}

public class Program

{

private static void Show(string[] ns)

{

foreach (string name in ns)

Console.WriteLine(“Name: ” + name);

}

static void Main(string[] args)

{

string[] names = new string[5];

Console.WriteLine(“Length of names = ” + names.Length.ToString());

Console.WriteLine(“”);

names[0] = “Alexander”;

names[1] = “Paulette”;

names[2] = “Gertrude”;

names[3] = “Hélène”;

names[4] = “Patricia”;

Show(names);

Routine.IncreaseArray(ref names, 5);

Console.WriteLine(“\nLength of names = ” + names.Length.ToString());

Console.WriteLine(“”);

names[5] = “Alain”;

names[6] = “Gerogette”;

Show(names);

Console.WriteLine(“”);

}

}

}

This would produce:

Length of names = 5

Name: Alexander

Name: Paulette

Name: Gertrude

Name: Hélène

Name: Patricia

Length of names = 10

Name: Alexander

Name: Paulette

Name: Gertrude

Name: Hélène

Name: Patricia

Name: Alain

Name: Gerogette

Name:

Name:

Name:

Press any key to continue . . .

 

Advertisements

One thought on “.Net interview questions asked in capgemini

Thanks a lot for visiting this site .. Please leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s