1,056 questions
-3 votes
1 answer
102 views
How can I pass a reference to an internal class upon construction of a public-facing subclass without violating nullabe safety?
I'm not super experienced with C#, and this is a bit of a puzzle. Consider the following code: #nullable enable using System.Collections.Generic; // Biology.dll public abstract class Animal { ...
3 votes
1 answer
113 views
Platform dependent implementations with return values do not work in MAUI
I have problems to implement any platform dependent classes in a MAUI project. The compiler produces errors if I use a method which has a return value. I implemented the function first for each ...
-1 votes
1 answer
49 views
Visibility Modifiers in Spring / Kotlin [closed]
Is it bad practice to use private to hide the implementation of a contract and not show it even in ide autocomplet. If so, why? interface MyService { fun process() } @Service private class ...
3 votes
1 answer
128 views
Microsoft.ML C# properties of internal input class must be public otherwise error
I'm working on an ML.NET project where I load data into an IDataView, apply an ONNX model transformation, and then access the transformed output. My Input class is in the same assembly as my Output ...
0 votes
1 answer
62 views
Change in object properties after change in access modifier
In my Student class, the variable is first set to: public String name; I access this in the other class named StudentUse class as follows: Student s1 = new Student(); s1.name= "sarang"; ...
-1 votes
1 answer
61 views
Java Protected Field Access Issue in Subclass
What is the difference between public, protected, package-private and private in Java? The question's answer cannot answer my question. It's not a duplicate question. I totally know the diagram of ...
0 votes
0 answers
66 views
Refactor multiple public classes in a folder/namespace to internal classes
Imagine 10 public classes in a folder/namespace. I want to make all of them internal. Any way to do this using Rider without modifying each file manually?
4 votes
3 answers
216 views
Why can't I access the public method after overriding a protected method?
I have a question about access modifiers override. First, let's look at the following code. fun main() { val b: AAA = BBB() b.testA() } open class AAA { fun testA() { println(&...
3 votes
5 answers
212 views
How to propagate the value of an init-only property to an enclosed class?
I have a Wheel class with two init-only properties Spokes and DiskBrake: public class Wheel { internal Wheel() { } public int Spokes { get; init; } public bool DiskBrake { get; init; } } ...
2 votes
0 answers
135 views
How to detect classes marked with file modifier
In C# 11, the new file type modifier was introduced. I was looking for a way to detect such non-public type using reflection, however, I have not find any "good" way to do so. There is no Is…...
2 votes
2 answers
463 views
Why can't I declare a private member of a file-local type in another class within the same file?
This code: public class Class1 { private Class2 _class2; private void Something() { Class2 class2; } } file class Class2 { } produces compiler error CS9051 on the member ...
1 vote
1 answer
169 views
Scala case class: Is public var member possible?
Scala noob here, but while learning about case classes, I see the members are by default read-only. However, if you add var, they become private; and there is no public access modifier. Any way to ...
4 votes
3 answers
339 views
Python access modifiers as a decorator
Is it possible to implement protected and private access modifiers for classes with decorators in python? How? The functionality should be like the code below: class A: def public_func(self): ...
0 votes
0 answers
90 views
Why is overriding necessary for the clone() method in the class if we are calling the clone() on the instance of the class in some other class? [duplicate]
class Cat { int j; Cat(int j) { this.j = j; } } class Dog implements Cloneable { int i; Cat c; Dog(Cat c, int i) { this.c = c; this.i = i; } ...
1 vote
0 answers
363 views
What does a readonly modifier for a method do?
I write this code struct Test { public override string ToString() => "some text"; } Then I get a compiler message suggestion IDE0251 Member can be made 'readonly' this ...