الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

التحويل من اوبجيكت الى نوع كلاس اخر

مغلق
بدأه isdep_makin في 16 يوليو 2006 · 2 رد · 454 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمه الله وبركاته

اريد كيفيه التحويل من كلاس الى اوبجيكت والعكس

class player

{

public name as string

pubic age as integer

}

in the button event

dim play1 as player=new player ()

play1.name=" mohamed "

play1.age=22

i need to put this object play1 in colllection and the collection convert the player to object type

so i need to convert the object type to player type when i read the object from the collection

sorry need help i new in vb.net and have experince 3 years in c#

but vb.net is to starnge and have a very strange tecniques

Mohamed Makeen

Senior Software Developer

Egypt - Cairo

eng_makin@hotmail.com

0142003269

#2

اذا كنت تريد ان تضع الصنف الذي انشاته في مجموعة ، فيمكن ذلك عن طريق عمل صنف جديد يرث من صنف CollectionBase كلاتي:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

public class players : CollectionBase
{
	public player this[int index]
	{
		get
		{
			return ((player)List[index]);
		}
		set
		{
			List[index] = value;
		}
	}


	public int Add(player value)
	{
		return (List.Add(value));
	}

	public int Add(IGUISimpleItem value)
	{
		return (List.Add(value));
	}

	public int IndexOf(player value)
	{
		return (List.IndexOf(value));
	}

	public void Insert(int index, player value)
	{
		List.Insert(index, value);
	}

	public void Remove(player value)
	{
		List.Remove(value);
	}

	public bool Contains(player value)
	{
		// If value is not of type Int16, this will return false.
		return (List.Contains(value));
	}

	protected override void OnInsert(int index, Object value)
	{
		// Insert additional code to be run only when inserting values.
	}

	protected override void OnRemove(int index, Object value)
	{
		// Insert additional code to be run only when removing values.
	}

	protected override void OnSet(int index, Object oldValue, Object newValue)
	{
		// Insert additional code to be run only when setting values.
	}

	protected override void OnValidate(Object value)
	{
		//if (value.GetType() != typeof(player))
		//	throw new ArgumentException("value must be of type player ", "value");
	}


}

وعليه يمكنك التعامل مع الصنف players باعتبارة صنف مجموعة لل object الذي انشاته سابقا player

ملاحظة: الكود طبعا بال C# لكن يمكن تحويله الى VB او عمل ClassLibrary وانشاء ملف DLL وعمل Refrence له في برنمج الذي يعمل بال VB

وبالتوفيق

#3

السلام عليكم

شكرا جزيلا اخى على الرد

وجد الCONVERTER المنلسب

example

dim play1 as player=new player()

play1.name="mohamed"

play1.age=22

dim obj as object=ctype(play1,object)

when you need to get the target agin you write

dim pla as player=new player()

pla=ctype(obj,player)

شكرا مره اخرى والسلام عليكم ورحمه الله وبركاته

Mohamed Makeen

Senior Software Developer

Egypt - Cairo

eng_makin@hotmail.com

0142003269

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…