16,004,653 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by The_Unknown_Member (Top 42 by date)
The_Unknown_Member
9-Apr-18 8:27am
View
@Maciej Los Yes I know this.
The_Unknown_Member
9-Apr-18 7:07am
View
I meant that it won't work because List of T doesn't support covariance (classes can't support covariance + it will break the type safety in this case). The question is mostly about the second part
IList<derived> derived = new List<derived>();
IList <base /> basee = derived;
Specifically this line:
IList <base /> basee = derived;
Here I am allowed to cast the derived to IList<base /> (of course it will fail in runtime but here i'm talking about compile time). How did the compiler determine that
the derived list can be casted to IList? Does it care about the generic parameters? Or it just cares about the inheritance tree of List<t> so in this case IList<t> is implemented by List<t> hence the compiler allows me to cast my list to IList without caring about the generics. Is this the case?
The_Unknown_Member
1-Apr-18 7:12am
View
But the reference variable that points to a list of dogs is the interface "IList<dog>" so I am supposed to do an explicit cast to assign the list to the IEnumerable<animal> reference. But actually it works??
See this example:
static void Main()
{
IAnimal a = new Dog();
Bark(a);
}
static void Bark(Dog d)
{
Console.WriteLine("Baau baaau :@@@");
}
"Bark(a);" this code won't work unless I cast the argument explicitly to Dog.
The_Unknown_Member
1-Apr-18 5:59am
View
Is this behavior only happening with ternary operators?
The_Unknown_Member
23-Mar-18 15:23pm
View
One last question:How does FindAll not accept anything other than a boolean value. I want to know this particular detail of the implementation. It's a generic method but it works only with boolean values and when I try to return an int for example the compiler gives error: "Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type".
The delegate is generic too.
The_Unknown_Member
23-Mar-18 13:40pm
View
Thanks!!!
The_Unknown_Member
23-Mar-18 13:33pm
View
Ohhh, I got it... I'm passing the anonymous method to the Predecate<t> parameter of the method. Am I right?
The_Unknown_Member
18-Mar-18 7:33am
View
Oh it's an infinite recursion... I got the point. Thanks for clarifying!
The_Unknown_Member
18-Mar-18 7:02am
View
"No, because that doesn't make any sense to me! :laugh:
Try explaining again, with examples." Well You are right. It gives a StackOverflowException. Why is it giving a StackOverflowException? however it works fine with baseclass field in the derived class:
public class BaseClass
{
}
public class DerivedClass : BaseClass
{
public DerivedClass dc = new DerivedClass(); // Doesn't work at all
public BaseClass bc = new BaseClass(); // Works fine!!!
}
The_Unknown_Member
18-Mar-18 6:13am
View
Also the same is the case if you use a nested class like this:
class SomeRandomName
{
public InnerRandomClass irc = new InnerRandomClass();
public class InnerRandomClass
{
}
}
The_Unknown_Member
18-Mar-18 6:04am
View
So the instance field must contain data that is known at compile time or it should use a static method because the static class is created with its default static constructor before any instance object. Do I understand it correctly? But it works if you make the field an object reference that points to object of this type. Can you explain why this happens?
The_Unknown_Member
11-Mar-18 15:41pm
View
Well that's the question exactly. the returned object is of type System.Object. The why is it possible to cast the returned System.Object object to SimpleClass? It doesn't make sense. System.Object isn't SimpleClass but SimpleClass is System.Object
Edit: Maybe the compiler does something behind the scenes and makes the derived MemberwiseClone() method return a SimpleClass object in the implementation? Isn't it the case? This behavior happens only when using the derived MemberwiseClone() method from the SimpleClass.
The_Unknown_Member
9-Mar-18 10:17am
View
Are values of fields and properties set to their defaults within the constructor?
The_Unknown_Member
30-Jul-17 16:33pm
View
Not compiling. Here is the error message (its a screenshot just open the link):
https://i.gyazo.com/bfd20571fb65d0ed231aa5c10720065d.png
The_Unknown_Member
29-Jul-17 3:24am
View
"MSIL is converted to native code (i.e. binary code that can execute directly on the actual processor) by the JIT compiler on a method-by-method basis, not line by line"
And after that how the native code is executing ? Is it line by line ? Because I think if it wasn't line by line then we couldn't have Run-Time time
The_Unknown_Member
28-Jul-17 17:29pm
View
@Richard MacCutchan Can you also explain me how the Assembly code executes ? For example lets assume we have a program of 100 lines assembly code and when this assembly code start assembling from Assembly to a Native code is it doing it line by line or doing all at once ?
The_Unknown_Member
21-Jul-17 5:10am
View
Okay could you explain me this please:
object o = 5;
object y = 6;
object oy = o + y;
Console.WriteLine(oy.GetType());
This is still polymorphishm. Because every class in .NET inherits from the System.Object so i can assign to variable of type System.Object an integer value and the type of this variable in run-time will be integer and in compile-time it will be System.Object. I know that the System.Object has no operator overload "+" for integer numbers but shouldn't it perform o + y in runtime and assign it back to the variable oy ?
Edit: I think I understood this. This is because after the assignment operator of oy I am adding two variables of type System.Object (which are holding integers but in compile-time they are still System.Object) and since System.Object does not support arithmetic operations for integers it cant perform the task in runtime but if i make it object oy = 5 + 6; then it will can because 5 and 6 are integer literals and are not holded by System.Object variable. Did I understand it right ?
The_Unknown_Member
19-Jul-17 7:54am
View
I dont have any plugins installed externally. Its freshly installed Visual Studio 2015 Community Edition Update 3 (the latest one). I resetted all the settings by default but again the same problem. And if you are wondering why I am still using VS 2015 thats because VS 2017 feels "kinda" unstable and buggy.
The_Unknown_Member
19-Jul-17 4:34am
View
But the funniest thing is that I am working on the same file and the same namespace in which this class is defined. I recorded a GIF to show you: https://i.gyazo.com/2472900210f4e15b5f830e4b033e9b70.mp4
The_Unknown_Member
17-Jul-17 8:09am
View
Thanks!
The_Unknown_Member
14-Jul-17 13:32pm
View
I didn't mean this. Let me explain:
Lets assume that I have a char variable and I make this char variable static. So now my static char variable is stored in the static storage on the heap. So if this is on the heap why is it still able to overflow ?
The_Unknown_Member
13-Jul-17 6:44am
View
I also have another question. Lets say I have this array: char s[] = "string";
Since the arrays in C++ are pointers to a data in the memory and since the char is 1 byte so doing s[1] should be the same as s + 1 right ? But it does not compile ? Why ?
The_Unknown_Member
10-Jul-17 16:40pm
View
Thanks for the links! I checked them and I learned something new. But still it didn't answer my question. Since I am bad with the explainations I will show you new piece of code:
using System;
namespace ConsoleApplication2
{
class Program
{
public static void Main()
{
int i; // i variable declaration
{
i = 5; // initialization in the inner block
}
Console.WriteLine(i); // And how here I am able to call it from the outer block ? Isn't the value assigned to i available only in the inner block ?
}
}
}
The_Unknown_Member
10-Jul-17 4:14am
View
This is kinda confusing. How is it even possible ? For example why I cant do this:
public static void Main()
{
int i;
for (int J = 0; J < 10; J++)
{
i = 10;
}
Console.WriteLine(i);
}
Please explain me everything man. Thanks!
The_Unknown_Member
7-Jul-17 7:16am
View
I wanted to ask why when the array is defined as static and the array is outside the body of GetNames method, why the method is able to return it ?
The_Unknown_Member
5-Jul-17 14:12pm
View
This thing:
static string[] ret = { "Matthew", "Mark", "Luke", "John" };
static string[] GetNames()
{
return ret;
}
The_Unknown_Member
5-Jul-17 9:42am
View
Its a little bit confusing
The_Unknown_Member
3-Jul-17 13:31pm
View
Yeah I know that. Also its calling the constructor of Employee.
The_Unknown_Member
3-Jul-17 12:00pm
View
I think I understood it:
Person p = new Employee();
Employee e = p as Employee;
So in the first line I am making Person reference with name "p" and making this reference pointing to an instance of the object Employee. But since the reference variable is of type Person I am able to see only the specific things for the Person class. In simple words: I am watching through the eyes of Person. And in the second line I am making an Employee reference variable with name "e" and making this "e" variable pointing to the same address to which "p" is pointing to but treated as an Employee.
Did I understand it in the right way ?
The_Unknown_Member
3-Jul-17 7:19am
View
Yeah It makes sense. You gave me a real world example and very thanks for that. But this wasn't what I asked. I am awful at explaining things to the people and I hate myself for that. Just look at this code and I think you will understand what I ask:
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<Person> people = new List<Person>();
people.Add(new Employee());
people.Add(new Student());
Person p = new Employee();
Employee e = p as Employee; // I want to ask what is happening in this line code when I do the cast in the assignment part
}
}
class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
class Employee : Person
{
public string ID { get; set; }
public void IntroduceSelf()
{
Console.WriteLine("Hello my name is {0} and my ID is {1}", Name, ID);
}
}
class Student : Person
{
public int GradeLevel { get; set; }
}
The_Unknown_Member
3-Jul-17 6:51am
View
Excellent. Just in 7 sentences you explained very well what is inheritance and polymorphism with a real world example. Thanks you a lot! Btw also these Russian dolls are called "Matryoshka" if you didn't know.
The_Unknown_Member
3-Jul-17 4:44am
View
Noooo. I wanted to ask how the cast is working in this example:
class Program
{
static void Main()
{
Shape s = new Circle();
Circle c = (Circle)s;
c.Draw();
}
}
Im aware of what is Polymorphism and how it works but I cant understand how the cast is working in this example. Also sorry for the bad explaination hope you got the point of what I mean.
The_Unknown_Member
29-Jun-17 16:14pm
View
I know that. But Im learning the POLYMORPHISM
The_Unknown_Member
29-Jun-17 16:08pm
View
explain me this line of code:
Student student = p as Student; < -------------
The_Unknown_Member
27-Jun-17 4:06am
View
I understood it. Thanks for explaining it to me! :)
The_Unknown_Member
26-Jun-17 8:08am
View
But If I declare and initialize a field in one statement its working. For example:
public string name = "Bob"; // Working
but this wont work:
public string name; // Declaring the field
name = "Bob"; // Initializing the field in the same class
The_Unknown_Member
26-Jun-17 6:33am
View
But if initialize the field "name" in the Parent class it will work. So why there is problem when i want to initialize the field "name" from the derived class ? I just cant understand
The_Unknown_Member
5-Jun-17 14:19pm
View
Thanks!
The_Unknown_Member
29-May-17 5:33am
View
Thank you also for the answer!
The_Unknown_Member
29-May-17 5:33am
View
Thanks you man! Now I understood that there is no problem if i dont make my methods static in the class i will have to make instance of my class before use them. Like this for example:
using System;
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.divide(4, 2);
}
void divide(int a, int b)
{
Console.WriteLine(a / b);
}
}
The_Unknown_Member
21-May-17 15:17pm
View
Okay very thanks you!
The_Unknown_Member
21-May-17 3:18am
View
You mean because it's function prototype is in the Sally class ?
Show More