Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
public class Program
{
static void Main(string[] args)
{
Test test = new Test();
Console.WriteLine(test.GetType()); // -> it´s Test, of course
int a = 5;
Console.ReadLine();
}
}
public class Test
{
public string Name;
}
In the above case
the Type of "test" is Test, right?
And in this case the Type of "a" is int, named primitive data type,
public is an access modifier
So my Question now is, what is class then? A keyword? A primitive Datatype? Neither, Nor?
Please, don't explain my, what a class is doing or what's the difference between class or object, I know a class is like a construction plan.
Class is a keyword that signifies to the C# compiler that a class is being declared. See https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I check that number of instances created for a particular type and how much memory each instance occupied. Please give an example.
As suggested in the comment i will add an example
public class Myclass
{
private static long Count;
public Myclass()
{
Interlocked.Increment(ref Count);
}
}
This will only work for your own class, In this way you can't find out the number of instances of System.String for example.
To find out the size of a class, You should use this using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public class MyClass
{
public int MyField;
public int MyField;
}
And:
int sizeInBytes = Marshal.SizeOf(typeof(MyClass)); //return 8
Also you have here a list with size of int, byte, etc.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a handful of variables passed from one form to another, but now I'm realizing these variables can't be accessed outside the form method.
public Form3(int str, int dex, int vit, int arc, int hp, int mp, int sp, string name, string charClass)
{
...
}
I'd like to be able to access the arguments from other methods. Is it possible to increase the scope of these arguments within the class itself, or do I need to go to the roots and declare them differently?
Make them class-level members. For example:
public class Form3
{
private int Str { get; set; }
public Form3(int str)
{
Str = str;
}
private void SomeOtherMethod()
{
// here you can access Str
}
// other methods, etc.
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I get this error object reference is required on clindID in the submethod
Why can't I access the string clientID in the sub class Methods? I'd like to use it in multiple methods.
class Remote
{
public string clientID
{
set{} get { return this.clientID; }
}
public bool validClientId()
{
clientID="32";
return true;
}
// closing bracket?
Or would it be better to use
string clientID="";
which doesn't work either
You don't have a setter implemented.
public string clientID
{
get { return this.patientID; }
set { this.patientID = value; }
}
Because you didn't reference the variable using an object reference in your validClientId() method (as described by T McKeown's answer), your code is looking within the scope of the validClientId() method itself to find that variable. It can't find it because the variable hasn't been declared within that scope. Try including the object reference as described by T McKeown to force the compiler to look within the this object for that variable.
Also, your class brackets aren't closed. This might just be a problem with your example code, but you need a closing curly brace }
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How can I to check a property will be renewed or its value will be changed.
public MyClass A
{
get{}
set
{
// find if programmer set A=new MyClass();
}
}
It's not all clear what you want exactly, maybe something like this:
MyClass _a;
public MyClass A
{
get { return _a; }
set
{
// find if programmer set A=new MyClass();
if (value != _a)
{
// different value
}
}
}
For more complex scenario follow the suggestion of Raphaël Althaus and take a look at INotifyPropertyChanged.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to call a method in a fixed structure like below in C#:
var Test = new test1.test2.test3("parameter1","parameter2");
Is this possible in C#?
Here test1 and test2 can be classes and test3 is my method name and it will return string text.
I can manage if need to remove new keyword.
I am assuming it should something like this :-
Public class test1
{
Public class test2
{
Public string test3("parameter1","parameter2")
{
//Do something
}
}
}
Yes, you can if test3 is public structure type nested inside public structure type test2 which is nested inside test1
struct test1{
public struct test2{
public struct test3{
public test3(string p1,string p2) {/*do something*/}
//some params
}
//some params
//some params
}
Also test1 and test2 could be namespaces.