Hello Ankit,
@Jorge_Cavalcante is right, the C# code, inside a Invoke Code Activitiy, is like a Main method of a class. To meet your requirements you can use Lambda functions.
Action<string> GetUserName = (string username) => {
Console.WriteLine(username);
};
try {
GetUserName(userName);
} catch(Exception ex){
}
Best regards
Stefan