Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 538257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:00:45+00:00 2026-05-13T10:00:45+00:00

How could I make this work?: public class myClass { public string first; public

  • 0

How could I make this work?:

public class myClass
{
 public string first;
 public int second;
 public string third;
}

public string tester(object param)
{
 //Catch the name of what was passed not the value and return it
}

//So:
myClass mC = new myClass();

mC.first = "ok";
mC.second = 12;
mC.third = "ko";

//then would return its type from definition :
tester(mC.first) // would return : "mc.first" or "myClass.first" or "first"
//and 
tester(mC.second) // would return : "mc.second" or "myClass.second" or "second"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:00:45+00:00Added an answer on May 13, 2026 at 10:00 am

    In the absence of infoof, the best you can do is Tester(() => mC.first) via expression trees…

    using System;
    using System.Linq.Expressions;
    public static class Test
    {
        static void Main()
        {
            //So:
            myClass mC = new myClass();
    
            mC.first = "ok";
            mC.second = 12;
            mC.third = "ko";
            //then would return its type from definition :
            Tester(() => mC.first); // writes "mC.first = ok"
            //and 
            Tester(() => mC.second); // writes "mC.second = 12"
        }
        static string GetName(Expression expr)
        {
            if (expr.NodeType == ExpressionType.MemberAccess)
            {
                var me = (MemberExpression)expr;
                string name = me.Member.Name, subExpr = GetName(me.Expression);
                return string.IsNullOrEmpty(subExpr)
                    ? name : (subExpr + "." + name);
            }
            return "";
        }
        public static void Tester<TValue>(
            Expression<Func<TValue>> selector)
        {
            TValue value = selector.Compile()();
    
            string name = GetName(selector.Body);
    
            Console.WriteLine(name + " = " + value);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to make a code like this work: public class Func2<A,
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
What can I do to make this work: template<class C, class V, Test V::*>
Could anyone help me to make this port from Objective-C to MonoMac work? CGEventSourceRef
Could you help me to make this query faster. My query is workable, but
I know I could just make all the Mix_Musics public, and not worry about
I've been unable to make this work because of what I believe is a
so I'm trying to make this work and I can't seem to know why
Lets say I have a controller class like this. public class InStorePickupController : Controller
I have some POCO objects that look something like this: public class Foo {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.