d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Or C#
12Next
Add Reply New Topic New Poll
Member
Posts: 31,523
Joined: Mar 31 2004
Gold: 6.57
Nov 10 2015 01:21am
Need help let me know can help with school, projects won't do them for you but can answer questions or help guide u ..

Also can help with swift and objective c

Just remember "hello world" :)


Pm me if I don't respond right away


Always live by code etiquette

This post was edited by Katelyn on Nov 10 2015 01:32am
Member
Posts: 21,407
Joined: Jun 15 2007
Gold: 120,303.00
Dec 17 2015 01:22am
my program crashes i try to acces black[-1] and get sigsev offer 1fg for figs
Member
Posts: 31,523
Joined: Mar 31 2004
Gold: 6.57
Dec 21 2015 05:32pm
Quote (dos350 @ 17 Dec 2015 03:22)
my program crashes i try to acces black[-1] and get sigsev offer 1fg for figs



Show hole file
Member
Posts: 26,405
Joined: Aug 3 2011
Gold: 21,693.00
Feb 22 2016 05:37pm
How well are you with: linked list, arrays, and structs, classes and things of the various sort?
Member
Posts: 1,039
Joined: Jul 8 2008
Gold: 1,939.50
Feb 24 2016 12:12am
Quote (Cocoo @ Feb 22 2016 07:37pm)
How well are you with: linked list, arrays, and structs, classes and things of the various sort?


Basic programming techniques 101? Ya I passed that. Ask away.
Member
Posts: 12,786
Joined: May 17 2013
Gold: 4,010.00
Feb 24 2016 09:20am
Quote (Cocoo @ 23 Feb 2016 00:37)
How well are you with: linked list, arrays, and structs, classes and things of the various sort?


if you want good performance with arrays, iterate over a 3D one like this :lol: :

Code
for(i = 0; i < 256 ; i++)
for(j = 0; j < 256 ; j++)
for(k = 0; k < 256 ; k++)


This post was edited by Klexmoo on Feb 24 2016 09:21am
Member
Posts: 3,476
Joined: Jul 20 2015
Gold: 651.00
Feb 24 2016 09:37am
Quote (Klexmoo @ Feb 24 2016 09:20am)
if you want good performance with arrays, iterate over a 3D one like this :lol: :

Code
for(i = 0; i < 256 ; i++)
for(j = 0; j < 256 ; j++)
for(k = 0; k < 256 ; k++)


lol
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 24 2016 04:33pm
I was hoping you could help me out, mate.

You see if I have this Java program here:

Code


public abstract class Bag<T>
{
public static int Capactity = 0;
}

public class BagOfStrings extends Bag<String>
{
public BagOfStrings()
{
Capactity = 10;
}
}

public class BagOfBooleans extends Bag<Boolean>
{
public BagOfBooleans()
{
Capactity = 20;
}
}

public class Program
{
public static void main(String[] args)
{
Bag<String> strings = new BagOfStrings();
Bag<Boolean> booleans = new BagOfBooleans();

System.out.println(BagOfStrings.Capactity);
System.out.println(BagOfBooleans.Capactity);
}
}



And I tried to port it over to C#

Code

public abstract class Bag<T>
{
public static int Capactity { get; set; }
}

public class BagOfStrings : Bag<String>
{
public BagOfStrings()
{
Capactity = 10;
}
}

public class BagOfBooleans : Bag<Boolean>
{
public BagOfBooleans()
{
Capactity = 20;
}
}

public class Program
{
static void Main(string[] args)
{
Bag<String> strings = new BagOfStrings();
Bag<Boolean> booleans = new BagOfBooleans();

Console.WriteLine(BagOfStrings.Capactity);
Console.WriteLine(BagOfBooleans.Capactity);
Console.Read();
}
}


Can you tell me what the issue is? Can you explain the difference between how generics are handled between the two languages? What does C# do differently than Java?
Member
Posts: 1,799
Joined: Aug 30 2015
Gold: 0.30
Warn: 10%
Mar 8 2016 05:51pm
Quote (Katelyn @ Nov 10 2015 02:21am)
Need help let me know can help with school, projects won't do them for you but can answer questions or help guide u ..

Also can help with swift and objective c

Just remember "hello world" :)


Pm me if I don't respond right away


Always live by code etiquette


can you tutor me? I'll pay fg if you're good (C)
I have some experience, of course. Not for a class by the way.

This post was edited by Arkil on Mar 8 2016 05:54pm
Member
Posts: 12,786
Joined: May 17 2013
Gold: 4,010.00
Mar 9 2016 06:32am
Quote (Minkomonster @ 24 Feb 2016 23:33)
I was hoping you could help me out, mate.

You see if I have this Java program here:

And I tried to port it over to C#

Code
public abstract class Bag<T>
{
public static int Capactity { get; set; }
}

public class BagOfStrings : Bag<String>
{
public BagOfStrings()
{
Capactity = 10;
}
}

public class BagOfBooleans : Bag<Boolean>
{
public BagOfBooleans()
{
Capactity = 20;
}
}

public class Program
{
static void Main(string[] args)
{
Bag<String> strings = new BagOfStrings();
Bag<Boolean> booleans = new BagOfBooleans();

Console.WriteLine(BagOfStrings.Capactity);
Console.WriteLine(BagOfBooleans.Capactity);
Console.Read();
}
}


Can you tell me what the issue is? Can you explain the difference between how generics are handled between the two languages? What does C# do differently than Java?


I don't see any issue?
C# generics are a part of the language all the way through the CLR, and generics in Java are (afaik) compiled to typecasts and are not "real" generics.
You can use simple type notation in C# (can use string in lower case and Boolean -> bool in C#, not that it matters though)

*edit:
I ran the program in Java and the output is different so I guess I was wrong.

I think it has something to do with how abstract classes work in Java vs C# but I'm not entirely sure, as I don't code in Java.

Each instantiation you do (in your C# example) of BagOfStrings and BagOfBooleans calls the individual constructors.
The reason I think that they aren't the same value when printing to the console, is that you print the value of the integer for each individual instance, even though it's a static variable.

Abstract classes in C# aren't meant to be instantiated, so I think (I'm not 100% on this) that you simply have the static variable as a member of each BagOfStrings and BagOfBooleans, rather than them sharing the same static variable from their parent class, because the abstract class is never instantiated.

This post was edited by Klexmoo on Mar 9 2016 06:53am
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll