how to create Const Member methods inside a class. how to create const objects of a Class.
-
how to create Const Member methods inside a class. how to create const objects of a Class. Class Base { int member1=10; public void ModifyMember() // I need to make this method Const { member1 +=1; } } //In Main public static void Main() { //how to creat cons objects of class Base }
-
how to create Const Member methods inside a class. how to create const objects of a Class. Class Base { int member1=10; public void ModifyMember() // I need to make this method Const { member1 +=1; } } //In Main public static void Main() { //how to creat cons objects of class Base }
Perhaps you mean 'static', not 'constant'?
-
how to create Const Member methods inside a class. how to create const objects of a Class. Class Base { int member1=10; public void ModifyMember() // I need to make this method Const { member1 +=1; } } //In Main public static void Main() { //how to creat cons objects of class Base }
Can't really, however, the example below is close and may introduce some concepts that will get you close to your goal.
public static class Program{
private static readonly Foo mFoo; public static void Main(){ //code here } static Program(){ mFoo = new Foo(1); }
}
public class Foo{public int Value{ get; private set; } public Foo(int value){ Value = value; }
}
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
how to create Const Member methods inside a class. how to create const objects of a Class. Class Base { int member1=10; public void ModifyMember() // I need to make this method Const { member1 +=1; } } //In Main public static void Main() { //how to creat cons objects of class Base }
There is no such thing as a Const method. Perhaps you're thinking about a Static method? Also, there is no such thing as a class declared as Const. Again, you're thinking about static??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
how to create Const Member methods inside a class. how to create const objects of a Class. Class Base { int member1=10; public void ModifyMember() // I need to make this method Const { member1 +=1; } } //In Main public static void Main() { //how to creat cons objects of class Base }
Perhaps this is what you wanted..?
public static class Foo
{
public static int AddOne(int Input)
{
return ++Input;
}
}class Program
{
static void Main(string[] args)
{
Console.WriteLine(Foo.AddOne(1));
Console.Read();
}
} -
Can't really, however, the example below is close and may introduce some concepts that will get you close to your goal.
public static class Program{
private static readonly Foo mFoo; public static void Main(){ //code here } static Program(){ mFoo = new Foo(1); }
}
public class Foo{public int Value{ get; private set; } public Foo(int value){ Value = value; }
}
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Thanks. How do you create a method , which will only be allowed to read the data Members, but can not be allowed to modify the data of the object . The static method, can still modify the static data members of the class.
-
Thanks. How do you create a method , which will only be allowed to read the data Members, but can not be allowed to modify the data of the object . The static method, can still modify the static data members of the class.
The only static method is Main and it cannot change the value of mFoo since it is read only. Furthermore, the Value property in Foo has a private set property meaning that only the public property is generally accessible.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
how to create Const Member methods inside a class. how to create const objects of a Class. Class Base { int member1=10; public void ModifyMember() // I need to make this method Const { member1 +=1; } } //In Main public static void Main() { //how to creat cons objects of class Base }
-
Thanks. How do you create a method , which will only be allowed to read the data Members, but can not be allowed to modify the data of the object . The static method, can still modify the static data members of the class.