steven preadly
steven preadly
Explore posts from servers
CC#
Created by steven preadly on 7/4/2024 in #help
✅ how can i improve this code ?
c#
c#
78 replies
KPCKevin Powell - Community
Created by steven preadly on 6/29/2024 in #front-end
what are the ways that i can follow to mange the height in card created using bootstrap
No description
17 replies
KPCKevin Powell - Community
Created by steven preadly on 6/20/2024 in #front-end
Why is the <div> with position-absolute and start-100 positioned outside the container?
No description
17 replies
CC#
Created by steven preadly on 5/28/2024 in #help
can I ask about your opinion for this description that prove that structs is value type
c#
/*
* in this example we have a structure and a class
* and those are done to prove the statment above
* that the struct is a value type while the class is
* refrence type
*/
public struct Point
{
public int x;
public int y;
}


class MyClass
{
public int x;
}

internal class Program
{
private static void Main(string[] args)
{
/*
* in here we used the struct we inilize it with a value x = 10
* and y = 20
*/
Point p1 = new Point { x = 10, y = 20 };

// then we write the value of x to the console
// it gets (10)
Console.WriteLine(p1.x);

//we used the ModifayStruct(Point P1) and we passed the P1 struct to it
// where this method modifayes the p1.x value to 12 other than 10
ModifayStruct(p1);

// the result when writting to the console is 10
// this is happiesn becuse the struct is a value type when we passed the struct to
// a method we are passing a copy of the struct not an adress to it in the memory
Console.WriteLine(p1.x);


/*
* in here we instatiated a mew Myclass object with x feild is 10
*/
MyClass @class = new MyClass { x = 10 };

// we used the ModifayClass(MyClass obj) and passed the above object to it
// where this method modifies x feild inside of it
ModifayClass(@class);

// the result is that x got modified that becuse when we passed a refrence varible to the
// method it got passed by refrence whicj means we are passng the address of that object
// to the method
Console.WriteLine(@class.x);

}

// modifays the point structs feild x to 12
public static void ModifayStruct(Point p1)
{
p1.x = 12;
}

// modifays the point class feild x to 12
public static void ModifayClass(MyClass obj)
{
obj.x = 12;
}
}
c#
/*
* in this example we have a structure and a class
* and those are done to prove the statment above
* that the struct is a value type while the class is
* refrence type
*/
public struct Point
{
public int x;
public int y;
}


class MyClass
{
public int x;
}

internal class Program
{
private static void Main(string[] args)
{
/*
* in here we used the struct we inilize it with a value x = 10
* and y = 20
*/
Point p1 = new Point { x = 10, y = 20 };

// then we write the value of x to the console
// it gets (10)
Console.WriteLine(p1.x);

//we used the ModifayStruct(Point P1) and we passed the P1 struct to it
// where this method modifayes the p1.x value to 12 other than 10
ModifayStruct(p1);

// the result when writting to the console is 10
// this is happiesn becuse the struct is a value type when we passed the struct to
// a method we are passing a copy of the struct not an adress to it in the memory
Console.WriteLine(p1.x);


/*
* in here we instatiated a mew Myclass object with x feild is 10
*/
MyClass @class = new MyClass { x = 10 };

// we used the ModifayClass(MyClass obj) and passed the above object to it
// where this method modifies x feild inside of it
ModifayClass(@class);

// the result is that x got modified that becuse when we passed a refrence varible to the
// method it got passed by refrence whicj means we are passng the address of that object
// to the method
Console.WriteLine(@class.x);

}

// modifays the point structs feild x to 12
public static void ModifayStruct(Point p1)
{
p1.x = 12;
}

// modifays the point class feild x to 12
public static void ModifayClass(MyClass obj)
{
obj.x = 12;
}
}
3 replies
CC#
Created by steven preadly on 5/28/2024 in #help
When should i use Private constractor with factory method?
here included example
c#
public class Student
{

private string name;
private Student(string name)
{
this.name = name;
}

public static Student CreateObject(string name)
{
return new Student(name);
}

public string Name
{
get { return name; }
}


}
c#
public class Student
{

private string name;
private Student(string name)
{
this.name = name;
}

public static Student CreateObject(string name)
{
return new Student(name);
}

public string Name
{
get { return name; }
}


}
12 replies
CC#
Created by steven preadly on 5/27/2024 in #help
Calculating Student Grade Book Average (GBA) in Percent - Encountering Zero Value Issue
I'm working on a student class with properties mark and totalMark. My goal is to define the totalMark property to compute the GBA as a percentage. However, every time I implement the calculation, the totalMark value consistently returns 0.
c#
public class Student
{

private int totalmarks;

public string? Name { get; set; }

public int Marks { get; set; }

public int TotalMarks
{
get
{
return (this.Marks / 250) * 100;
}
}

}

Student student = new Student();

student.Marks = 120;

int gba = student.TotalMarks;

Console.WriteLine(gba);
c#
public class Student
{

private int totalmarks;

public string? Name { get; set; }

public int Marks { get; set; }

public int TotalMarks
{
get
{
return (this.Marks / 250) * 100;
}
}

}

Student student = new Student();

student.Marks = 120;

int gba = student.TotalMarks;

Console.WriteLine(gba);
63 replies
CC#
Created by steven preadly on 5/26/2024 in #help
is the method hiding considered a type of polymorphisim?
is the method hiding considered a type of polymorphisim?
2 replies
CC#
Created by steven preadly on 5/24/2024 in #help
Polymorphism
dose the below sentence simply describes the meaning of Polymorphism
polymorphism is a Opp pillar that treats the objects created from derived class as a base class at runtime
polymorphism is a Opp pillar that treats the objects created from derived class as a base class at runtime
as an example in here the reference variable is pointing to the Employee base class while at run time the method is called on the PartTimeEmployee() type correct ?
c#
public class Employee
{
public string? firstName = "FN";
public string? lastName = "LN";

public virtual void PrintFullName()
{
Console.WriteLine(firstName + " " + lastName);
}
}

public class PartTimeEmployee: Employee
{
public override void PrintFullName()
{
Console.WriteLine(firstName + " " + lastName + " - PartTime");
}
}
Employee employee = new PartTimeEmployee();

employee.PrintFullName();
c#
public class Employee
{
public string? firstName = "FN";
public string? lastName = "LN";

public virtual void PrintFullName()
{
Console.WriteLine(firstName + " " + lastName);
}
}

public class PartTimeEmployee: Employee
{
public override void PrintFullName()
{
Console.WriteLine(firstName + " " + lastName + " - PartTime");
}
}
Employee employee = new PartTimeEmployee();

employee.PrintFullName();
and that is polymorphisim we have a base class method in one class(type) that can have many forms in drived class and the type that the method are called from is defined at runtime
2 replies
CC#
Created by steven preadly on 5/23/2024 in #help
Why does calling the PrintFullName() method require casting it as ((Employee)PTE).PrintFullName() ?
Hi, I have two classes where one inherits from the other. Here's the code. My question is: why do I need to cast the method PrintFullName() when calling it as ((Employee)PTE).PrintFullName()? Why can't it be cast directly like (Employee)PTE.PrintFullName()?
c#
public class Employee
{
public string? firstName;
public string? lastName;

public virtual string PrintFullName()
{
//Console.WriteLine(firstName + " " + lastName);

return firstName + " " + lastName;
}
}

public class PartTimeEmployee: Employee
{
public new string PrintFullName()
{
return firstName + " " + lastName + " " + "contractor";
}
}
c#
public class Employee
{
public string? firstName;
public string? lastName;

public virtual string PrintFullName()
{
//Console.WriteLine(firstName + " " + lastName);

return firstName + " " + lastName;
}
}

public class PartTimeEmployee: Employee
{
public new string PrintFullName()
{
return firstName + " " + lastName + " " + "contractor";
}
}
c#
PartTimeEmployee PTE = new PartTimeEmployee();
PTE.firstName = "parttime";
PTE.lastName = "Employee";
((Employee)PTE).PrintFullName();
c#
PartTimeEmployee PTE = new PartTimeEmployee();
PTE.firstName = "parttime";
PTE.lastName = "Employee";
((Employee)PTE).PrintFullName();
19 replies
CC#
Created by steven preadly on 5/21/2024 in #help
How can I get the memory address of a feilds in C#?
created an object from a class in C#. Is it possible to retrieve its memory location and address using C# code? i have tried this code but i got error at this line IntPtr address = GCHandle.AddrOfPinnedObject(handle); of the code
c#
Person person_1 = new Person("mina remon shaker");
FieldInfo? fieldInfo = typeof(Person).GetField("Name");
GCHandle handle = GCHandle.Alloc(person_1, GCHandleType.Pinned);
IntPtr address = GCHandle.AddrOfPinnedObject(handle);
handle.Free();
Console.WriteLine("Object address: 0x{0:X}", address.ToInt64());
c#
Person person_1 = new Person("mina remon shaker");
FieldInfo? fieldInfo = typeof(Person).GetField("Name");
GCHandle handle = GCHandle.Alloc(person_1, GCHandleType.Pinned);
IntPtr address = GCHandle.AddrOfPinnedObject(handle);
handle.Free();
Console.WriteLine("Object address: 0x{0:X}", address.ToInt64());
`
37 replies