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
Pandu
NA
18
19.7k
C# call by ref function
Sep 27 2013 1:10 PM
Following is my c# code. I have a solution function which has return type int and a string is passed through it. My aim is to get the middle index character in the string and left side of string should be reverse of right side of the string. eg 'rac
E
car'. In this E is middle character and rac and car are reverse substrings. I am getting errors at return statement and in Main when I call my solution fucntion passing the parameter as 'S' I am not able to get that basic mistake I am doing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Solution
{
class Program
{
public int solution(String S)
{
int mid = S.Length / 2;
string leftS = S.Substring(0, mid);
string revleftS = "";
for (int index = leftS.Length - 1; index >= 0; index--)
{
revleftS += leftS[index];
}
string rightS = S.Substring(mid + 1);
if (revleftS.CompareTo(rightS) == 0)
{
Console.WriteLine(mid);
Console.ReadKey();
}
else
{
Console.WriteLine("left and right part of strings are not equal : -1");
Console.ReadKey();
}
return ;
//here I am getting error
}
static void Main(string[] args)
{
Console.WriteLine("enter a string :");
string S = Console.ReadLine();
Convert.ToInt32(solution(S));
//here I am getting error as object reference is required for the non-static field, method, or property
//'Solution.Program.solution(string)'
}
}
}
Reply
Answers (
3
)
Getting/Retrieving Sharepoint 2013 List data
how to create a software define radio ?