Assume i have a class:
public class Products
{
public string ID { get; set; }
public string Name { get; set; }
public string GetItemName() { ... }
public void SetItemName() { ... }
public string GetItemID() { ... }
public void SetItemID() { ... }
//...
}
It is any way to make all the properties or method inherits the parent class’s access modifiers,so i don’t have to assign [public] to each of properties/method.
That’s not C# code, that’s C++. A language that doesn’t support properties, but does support this:
Which is probably what you are really asking for. No, never make the mistake of comparing C# to C++, it resembles the language only in passing. The accessor keyword must be applied to every member. Good thing is, you’ll have a lot less of them. Delete the GetItemName and SetItemName methods, the Name property is all you need.
Here’s an old magazine article that might be useful to you, “C++ -> C#: What You Need to Know to Move from C++ to C#“