Thursday 31 May 2012

practical interview questions of c#



Q. Write a program in C# that take string input, and print its number of characters.

string name = Console.ReadLine();
Console.WriteLine(name.Length);
Console.ReadLine();

Q. Write a program in C Sharp that take a sentense as input, and show the number of "a" used in the sentense.

string name = Console.ReadLine();
int counter = 0;
for (int i = 0; i < name.Length; i++)
{
if (name[i] == 'a')
{
counter++;
}

Saturday 19 May 2012

Program of palindrome in c#

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args) {
string str=string .Empty ;
Console.WriteLine("Enter a String name");
string s = Console.ReadLine();
int i = s.Length;
//we can get the Length of string by using Length Property

Friday 18 May 2012

Main difference between web user control & custom control in asp.net

This is from Microsoft's site:
Web user controls
  • Easier to create
  • Limited support for consumers who use a visual design tool
  • A separate copy of the control is required in each application
  • Cannot be added to the Toolbox in Visual Studio
  • Good for static layout

Thursday 17 May 2012

In C# Reverse String Program

public string reverse(string str)
{

int len=str.length;
Char[] arr=new Char[len];
for(int i=0;i<len;i++)
{
  arr[i]= str[len-1-i];
 }

In C# Reverse program of number

int n = 1234567;
int left = n;
int rev = 0;
while(left>0)
{
  r = left % 10;  
  rev = rev * 10 + r;
  left = left / 10; 
}

Console.WriteLine(rev);