Object member as a parameter of a function in C# [duplicate]
This question already has an answer here:
Update a property on an object knowing only its name
3 answers
How to set property value using Expressions? [duplicate]
1 answer
How set value a property selector Expression<Func<T,TResult>>
6 answers
I want to know how to put object member as a parameter of a function
class Student
{
public int id;
public string name;
public string year;
public Student(string i,string n,string y){
id=i;
name=n;
year=y;
}
}
class main{
Student s=new Student(1,"NAME","YEAR");
private static void Main(string args)
{
change();
}
void change(){
s.name="CHANGED";
}
}
This code may not have any point since this is just an example. All I want to know is how to put object member as a parameter. On void change(), I want to put a parameter to replace name, so that I can us this function to change both name and year. Example: Instead of void change() above:
void change(string m)//using string is not working
{
s.m="CHANGED";
}
On main function:
private static void Main(string args)
{
change(name);//s.name is now equal to CHANGED
change(year);//s.year is now equal to CHANGED
}
is it possible to do this?
THANK YOU
c# function object parameters
marked as duplicate by CodeCaster
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 9:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Update a property on an object knowing only its name
3 answers
How to set property value using Expressions? [duplicate]
1 answer
How set value a property selector Expression<Func<T,TResult>>
6 answers
I want to know how to put object member as a parameter of a function
class Student
{
public int id;
public string name;
public string year;
public Student(string i,string n,string y){
id=i;
name=n;
year=y;
}
}
class main{
Student s=new Student(1,"NAME","YEAR");
private static void Main(string args)
{
change();
}
void change(){
s.name="CHANGED";
}
}
This code may not have any point since this is just an example. All I want to know is how to put object member as a parameter. On void change(), I want to put a parameter to replace name, so that I can us this function to change both name and year. Example: Instead of void change() above:
void change(string m)//using string is not working
{
s.m="CHANGED";
}
On main function:
private static void Main(string args)
{
change(name);//s.name is now equal to CHANGED
change(year);//s.year is now equal to CHANGED
}
is it possible to do this?
THANK YOU
c# function object parameters
marked as duplicate by CodeCaster
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 9:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Using reflection, or using a property expression. But why would you want this? What problem are you trying to solve?
– CodeCaster
Nov 20 '18 at 9:47
I am try to sort out an object list(List in a class). Since the object list I want to sort has many variable and I want to sort by all of it, I want to create a function that can sort by every member of that object.
– Teng Vanndavid BLiZzaRD
Nov 20 '18 at 10:21
add a comment |
This question already has an answer here:
Update a property on an object knowing only its name
3 answers
How to set property value using Expressions? [duplicate]
1 answer
How set value a property selector Expression<Func<T,TResult>>
6 answers
I want to know how to put object member as a parameter of a function
class Student
{
public int id;
public string name;
public string year;
public Student(string i,string n,string y){
id=i;
name=n;
year=y;
}
}
class main{
Student s=new Student(1,"NAME","YEAR");
private static void Main(string args)
{
change();
}
void change(){
s.name="CHANGED";
}
}
This code may not have any point since this is just an example. All I want to know is how to put object member as a parameter. On void change(), I want to put a parameter to replace name, so that I can us this function to change both name and year. Example: Instead of void change() above:
void change(string m)//using string is not working
{
s.m="CHANGED";
}
On main function:
private static void Main(string args)
{
change(name);//s.name is now equal to CHANGED
change(year);//s.year is now equal to CHANGED
}
is it possible to do this?
THANK YOU
c# function object parameters
This question already has an answer here:
Update a property on an object knowing only its name
3 answers
How to set property value using Expressions? [duplicate]
1 answer
How set value a property selector Expression<Func<T,TResult>>
6 answers
I want to know how to put object member as a parameter of a function
class Student
{
public int id;
public string name;
public string year;
public Student(string i,string n,string y){
id=i;
name=n;
year=y;
}
}
class main{
Student s=new Student(1,"NAME","YEAR");
private static void Main(string args)
{
change();
}
void change(){
s.name="CHANGED";
}
}
This code may not have any point since this is just an example. All I want to know is how to put object member as a parameter. On void change(), I want to put a parameter to replace name, so that I can us this function to change both name and year. Example: Instead of void change() above:
void change(string m)//using string is not working
{
s.m="CHANGED";
}
On main function:
private static void Main(string args)
{
change(name);//s.name is now equal to CHANGED
change(year);//s.year is now equal to CHANGED
}
is it possible to do this?
THANK YOU
This question already has an answer here:
Update a property on an object knowing only its name
3 answers
How to set property value using Expressions? [duplicate]
1 answer
How set value a property selector Expression<Func<T,TResult>>
6 answers
c# function object parameters
c# function object parameters
asked Nov 20 '18 at 9:45


Teng Vanndavid BLiZzaRDTeng Vanndavid BLiZzaRD
1
1
marked as duplicate by CodeCaster
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 9:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by CodeCaster
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 9:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Using reflection, or using a property expression. But why would you want this? What problem are you trying to solve?
– CodeCaster
Nov 20 '18 at 9:47
I am try to sort out an object list(List in a class). Since the object list I want to sort has many variable and I want to sort by all of it, I want to create a function that can sort by every member of that object.
– Teng Vanndavid BLiZzaRD
Nov 20 '18 at 10:21
add a comment |
1
Using reflection, or using a property expression. But why would you want this? What problem are you trying to solve?
– CodeCaster
Nov 20 '18 at 9:47
I am try to sort out an object list(List in a class). Since the object list I want to sort has many variable and I want to sort by all of it, I want to create a function that can sort by every member of that object.
– Teng Vanndavid BLiZzaRD
Nov 20 '18 at 10:21
1
1
Using reflection, or using a property expression. But why would you want this? What problem are you trying to solve?
– CodeCaster
Nov 20 '18 at 9:47
Using reflection, or using a property expression. But why would you want this? What problem are you trying to solve?
– CodeCaster
Nov 20 '18 at 9:47
I am try to sort out an object list(List in a class). Since the object list I want to sort has many variable and I want to sort by all of it, I want to create a function that can sort by every member of that object.
– Teng Vanndavid BLiZzaRD
Nov 20 '18 at 10:21
I am try to sort out an object list(List in a class). Since the object list I want to sort has many variable and I want to sort by all of it, I want to create a function that can sort by every member of that object.
– Teng Vanndavid BLiZzaRD
Nov 20 '18 at 10:21
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
Using reflection, or using a property expression. But why would you want this? What problem are you trying to solve?
– CodeCaster
Nov 20 '18 at 9:47
I am try to sort out an object list(List in a class). Since the object list I want to sort has many variable and I want to sort by all of it, I want to create a function that can sort by every member of that object.
– Teng Vanndavid BLiZzaRD
Nov 20 '18 at 10:21